Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions actions/setup/js/resolve_host_repo.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ async function main() {
core.info(`Same-repo invocation: checking out ${targetRepo} @ ${targetRef}`);
}

// Compute the repository name (without owner prefix) for use cases that require
// only the repo name, such as actions/create-github-app-token which expects
// `repositories` to contain repo names only when `owner` is also provided.
const targetRepoName = targetRepo.split("/").at(-1);

core.setOutput("target_repo", targetRepo);
core.setOutput("target_repo_name", targetRepoName);
core.setOutput("target_ref", targetRef);
}

Expand Down
27 changes: 27 additions & 0 deletions actions/setup/js/resolve_host_repo.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,33 @@ describe("resolve_host_repo.cjs", () => {
expect(mockCore.setOutput).toHaveBeenCalledWith("target_ref", "abc123def456");
});

it("should output target_repo_name when invoked cross-repo", async () => {
process.env.GITHUB_WORKFLOW_REF = "my-org/platform-repo/.github/workflows/gateway.lock.yml@refs/heads/main";
process.env.GITHUB_REPOSITORY = "my-org/app-repo";

await main();

expect(mockCore.setOutput).toHaveBeenCalledWith("target_repo_name", "platform-repo");
});

it("should output target_repo_name when same-repo invocation", async () => {
process.env.GITHUB_WORKFLOW_REF = "my-org/platform-repo/.github/workflows/gateway.lock.yml@refs/heads/main";
process.env.GITHUB_REPOSITORY = "my-org/platform-repo";

await main();

expect(mockCore.setOutput).toHaveBeenCalledWith("target_repo_name", "platform-repo");
});

it("should output target_repo_name without owner prefix when falling back to GITHUB_REPOSITORY", async () => {
process.env.GITHUB_WORKFLOW_REF = "";
process.env.GITHUB_REPOSITORY = "my-org/fallback-repo";

await main();

expect(mockCore.setOutput).toHaveBeenCalledWith("target_repo_name", "fallback-repo");
});

it("should include target_ref in step summary for cross-repo invocations", async () => {
process.env.GITHUB_WORKFLOW_REF = "my-org/platform-repo/.github/workflows/gateway.lock.yml@refs/heads/feature-branch";
process.env.GITHUB_REPOSITORY = "my-org/app-repo";
Expand Down
4 changes: 2 additions & 2 deletions actions/setup/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "es2020",
"target": "es2022",
"module": "commonjs",
"lib": ["es2020"],
"lib": ["es2022"],
"types": ["node"],
"allowJs": true,
"checkJs": true,
Expand Down
Loading