fix: resolve target repo checkout path in push_to_pull_request_branch handlers#28377
fix: resolve target repo checkout path in push_to_pull_request_branch handlers#28377
Conversation
…tBranchHandler When a workflow configures `target-repo` for `push_to_pull_request_branch`, call `findRepoCheckout` to resolve the subdirectory checkout path, ensuring patch generation runs from the correct directory rather than always using GITHUB_WORKSPACE root. Closes #21307 Agent-Logs-Url: https://github.com/github/gh-aw/sessions/b40b9f06-4916-453b-a852-db2c1a780448 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ion to test Agent-Logs-Url: https://github.com/github/gh-aw/sessions/b40b9f06-4916-453b-a852-db2c1a780448 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes push_to_pull_request_branch patch generation when a workflow targets a repo checked out into a subdirectory via push_to_pull_request_branch.target-repo, by resolving and using the correct checkout path.
Changes:
- Extend
pushToPullRequestBranchHandlerto callfindRepoCheckout()whenpush_to_pull_request_branch.target-repois configured (not only whenentry.repois provided). - Update the checkout-not-found error text to match the new behavior.
- Add tests covering the configured
target-repopath (error when not found; success when found, including correctrepo_cwdand branch detection).
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/safe_outputs_handlers.cjs | Resolve correct git working directory for patch generation when target-repo is configured. |
| actions/setup/js/safe_outputs_handlers.test.cjs | Add/adjust tests to validate configured target-repo checkout resolution and resulting behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 2
| expect(responseData.error).toContain("'path' input"); | ||
| }); | ||
|
|
||
| it("should return error when defaultTargetRepo checkout is not found and entry.repo is not set", async () => { |
There was a problem hiding this comment.
Test name mentions defaultTargetRepo, but the behavior under test is specifically the push_to_pull_request_branch.target-repo configuration path. Renaming the test to reference target-repo (or “configured target repo”) would make the intent clearer and avoid confusion with the fallback default-target-repo logic derived from env/context.
| it("should return error when defaultTargetRepo checkout is not found and entry.repo is not set", async () => { | |
| it("should return error when configured target-repo checkout is not found and entry.repo is not set", async () => { |
| error: | ||
| `Repository checkout not found for ${repoSlug}. Ensure the repository is checked out in this workflow using actions/checkout. ` + | ||
| "If checking out multiple repositories, use the 'path' input so the checkout can be located.", | ||
| error: `Repository '${itemRepo}' not found in workspace. Check out the target repo with a path in checkout. If checking out multiple repositories, use the 'path' input so the checkout can be located.`, |
There was a problem hiding this comment.
The checkout-not-found error message dropped the explicit actions/checkout mention that was in the previous wording. Consider adding it back (while still referencing the path input) so it’s immediately clear which step/input the workflow author needs to adjust.
| error: `Repository '${itemRepo}' not found in workspace. Check out the target repo with a path in checkout. If checking out multiple repositories, use the 'path' input so the checkout can be located.`, | |
| error: `Repository '${itemRepo}' not found in workspace. Check out the target repo with actions/checkout and set its 'path' input so the checkout can be located. If checking out multiple repositories, ensure each actions/checkout step uses the appropriate 'path' input.`, |
🧪 Test Quality Sentinel ReportTest Quality Score: 72/100
Test Classification Details
Flagged Tests — Requires Review
|
…usion handler Resolves #28374. When the target repo differs from the workflow repo, find its checkout directory using findRepoCheckout and pass cwd to every git exec call (fetch, checkout, am, push, ls-remote, rev-parse, rev-list, review-branch, fallback-branch, bundle ops, and pushSignedCommits). Agent-Logs-Url: https://github.com/github/gh-aw/sessions/3b1d2ad5-2971-4fdf-a11c-1bb150651885 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ec calls Agent-Logs-Url: https://github.com/github/gh-aw/sessions/3b1d2ad5-2971-4fdf-a11c-1bb150651885 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
Fixed in commit 82ecb33.
|
|
Hey
|
|
🩺 Examination complete! CI Failure Doctor has delivered the diagnosis. Prescription issued! 💊 |
🩺 CI Doctor DiagnosisChecked SummaryThe Failing Checks
Detailed AnalysisError 1 —
Fix: Spread the set into an array before passing: const checkoutResult = findRepoCheckout(itemRepo, process.env.GITHUB_WORKSPACE, { allowedRepos: [...allowedRepos] });Or change Error 2 —
Fix option A — always pass an explicit const pushedSha = await pushSignedCommits({
githubClient,
owner: repoParts.owner,
repo: repoParts.repo,
branch: branchName,
baseRef: remoteHeadBeforePatch || `origin/\$\{branchName}`,
cwd: repoCwd ?? process.env.GITHUB_WORKSPACE ?? process.cwd(),
gitAuthEnv,
});Fix option B — make Recommended Fixes
Prevention TipsWhen spreading a conditional object ( Analysis Steps
|
|
@copilot review all comments |
…larity Agent-Logs-Url: https://github.com/github/gh-aw/sessions/af16cbe6-1871-4390-9b68-5737f98974e0 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in 47c722f:
|
When a workflow targets a repo checked out in a subdirectory (e.g.
caido/proxy-frontendchecked out under./proxy-frontend), both the MCP handler and the conclusion handler were running git operations inGITHUB_WORKSPACEroot instead of the subdirectory — making all agent commits invisible and producing "No commits were found to push."Changes
safe_outputs_handlers.cjs— Extend thefindRepoCheckoutguard inpushToPullRequestBranchHandlerto also trigger whenpushConfig["target-repo"]is set, not only whenentry.repois explicitly passed by the agent:Uses
pushConfig["target-repo"](notdefaultTargetRepo) to avoid false-triggering on fallback values derived fromcontext.repo/GITHUB_REPOSITORY.safe_outputs_handlers.test.cjs— Add coverage for thetarget-repoconfig path: error when checkout not found, and successful branch detection + patch generation from the correct subdirectory.push_to_pull_request_branch.cjs— Fix the conclusion handler (which applies the patch and pushes to the branch) to also run all git operations in the target repo's checkout directory whenitemRepodiffers fromGITHUB_REPOSITORY:findRepoCheckoutand calls it when the target repo differs from the workflow repobaseGitOpts = repoCwd ? { cwd: repoCwd } : {}helper spread into every git exec call:ls-remote,fetch,rev-parse --verify,checkout -B,rev-parse HEAD, bundle fetch/merge/update-ref,git am, patch-failure diagnostics, review-branch and fallback-branchcheckout/push,pushSignedCommits,rev-list --count, and finalrev-parse HEADpush_to_pull_request_branch.test.cjs— Add two cross-repo tests: error when target repo not found in workspace, andcwdcorrectly passed to git exec calls when a subdirectory checkout exists.