Objective
Fix actions/setup/js/push_to_pull_request_branch.cjs (conclusion handler) to run all git operations (fetch, checkout, apply, push) in the target repo's checkout directory instead of the workspace root.
Context
Issue #21306: The conclusion handler already resolves the target repo slug but then runs git fetch, git checkout, git apply, and git push with no cwd, so they all run in the job's default working directory (workspace root) instead of the subdirectory where the target repo is checked out.
Approach
- Add
require('./find_repo_checkout.cjs') at the top of the file
- After resolving
itemRepo (the target repo slug) and before any git commands:
- If
itemRepo differs from process.env.GITHUB_REPOSITORY, call findRepoCheckout(itemRepo, process.env.GITHUB_WORKSPACE, { allowedRepos }). If not found, return { success: false, error: "Repository 'org/repo' not found in workspace..." }.
- Set
repoCwd = checkoutResult.path
- Pass
{ cwd: repoCwd, env: { ...process.env, ...gitAuthEnv } } to every exec.exec call for git (fetch, checkout, apply, push)
- Prefer explicit
cwd per exec call over process.chdir to avoid global state side effects
Files to Modify
actions/setup/js/push_to_pull_request_branch.cjs — main push/apply git block
Acceptance Criteria
Generated by Plan Command for issue #21306 · ● 147.1K · ◷
Objective
Fix
actions/setup/js/push_to_pull_request_branch.cjs(conclusion handler) to run all git operations (fetch, checkout, apply, push) in the target repo's checkout directory instead of the workspace root.Context
Issue #21306: The conclusion handler already resolves the target repo slug but then runs
git fetch,git checkout,git apply, andgit pushwith nocwd, so they all run in the job's default working directory (workspace root) instead of the subdirectory where the target repo is checked out.Approach
require('./find_repo_checkout.cjs')at the top of the fileitemRepo(the target repo slug) and before any git commands:itemRepodiffers fromprocess.env.GITHUB_REPOSITORY, callfindRepoCheckout(itemRepo, process.env.GITHUB_WORKSPACE, { allowedRepos }). If not found, return{ success: false, error: "Repository 'org/repo' not found in workspace..." }.repoCwd = checkoutResult.path{ cwd: repoCwd, env: { ...process.env, ...gitAuthEnv } }to everyexec.execcall for git (fetch, checkout, apply, push)cwdper exec call overprocess.chdirto avoid global state side effectsFiles to Modify
actions/setup/js/push_to_pull_request_branch.cjs— main push/apply git blockAcceptance Criteria
findRepoCheckoutis imported and called when target repo differs fromGITHUB_REPOSITORY{ cwd: repoCwd }optiongetGitAuthEnvis still applied for fetch/push operationsmake agent-finishpassesRelated to Make push_to_pull_request_branch cross-repo #21306