Skip to content

Commit 6d7fc80

Browse files
Copilotdsymepelikhan
authored
fix: create_pull_request branch guidance, PR-comment tool selection, and shallow clone fallback (#24123)
* Initial plan * fix: create_pull_request branch guidance, PR-comment tool selection, shallow clone fallback - Issue 1: Strengthen branch name guidance in safe_outputs_create_pull_request.md to make clear the branch parameter must match git branch --show-current exactly - Issue 2: Add pr_context_push_to_pr_branch_guidance.md with guidance to prefer push_to_pull_request_branch over create_pull_request when triggered by a PR comment. Inject it conditionally when push-to-pull-request-branch is configured. - Issue 3: Fetch base commit before git cat-file -e in create_pull_request.cjs fallback path to handle shallow clone (fetch-depth: 1) environments. Agent-Logs-Url: https://github.com/github/gh-aw/sessions/507fdac8-ffba-44f8-9607-afd77e808000 Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: Peli de Halleux <pelikhan@users.noreply.github.com>
1 parent 5380a02 commit 6d7fc80

9 files changed

Lines changed: 42 additions & 1 deletion

.github/workflows/craft.lock.yml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/mergefest.lock.yml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/poem-bot.lock.yml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/tidy.lock.yml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/setup/js/create_pull_request.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,16 @@ gh pr create --title '${title}' --base ${baseBranch} --head ${branchName} --repo
895895
} else {
896896
core.info(`Original base commit from patch generation: ${originalBaseCommit}`);
897897

898+
// In shallow clones (fetch-depth: 1) the base commit may not be locally available.
899+
// Attempt to fetch it explicitly before checking whether it exists.
900+
try {
901+
await exec.exec("git", ["fetch", "origin", originalBaseCommit, "--depth=1"]);
902+
} catch (fetchError) {
903+
// Non-fatal: the commit may already be available, or the server may not support
904+
// fetching individual SHAs (e.g. some GHE configurations). Log for troubleshooting.
905+
core.info(`Note: could not fetch base commit ${originalBaseCommit} explicitly (${fetchError instanceof Error ? fetchError.message : String(fetchError)}); will verify local availability next`);
906+
}
907+
898908
// Verify the base commit is available in this repo (may not exist cross-repo)
899909
await exec.exec("git", ["cat-file", "-e", originalBaseCommit]);
900910
core.info("Original base commit exists locally - proceeding with fallback");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
<pr-comment-tool-guidance>
3+
When triggered by a pull request comment, if you need to push code changes, prefer using `push_to_pull_request_branch` to add commits to the existing pull request branch rather than `create_pull_request` which opens a separate new pull request. Only use `create_pull_request` if the instructions explicitly ask you to create a new, separate pull request.
4+
</pr-comment-tool-guidance>

actions/setup/md/safe_outputs_create_pull_request.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
To create a pull request:
55
1. Make any file changes directly in the working directory.
6-
2. If you haven't done so already, create a local branch using an appropriate unique name.
6+
2. If you haven't done so already, create a new local branch using `git checkout -b <branch-name>` with an appropriate unique name.
77
3. Add and commit your changes to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Verify you haven't deleted or changed any files you didn't intend to.
88
4. Do not push your changes. That will be done by the tool.
99
5. Create the pull request with the create_pull_request tool from safeoutputs.
10+
11+
**Important**: The `branch` parameter in the create_pull_request tool **must exactly match the name of your current local git branch** — the branch you just committed to. You can verify this with `git branch --show-current`. Never invent or guess a branch name; always use the actual branch name from `git branch --show-current`. If you are on an existing branch (e.g. you checked out a PR branch), use that branch name.

pkg/workflow/prompt_constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
const (
1111
promptsDir = constants.GhAwRootDirShell + "/prompts"
1212
prContextPromptFile = "pr_context_prompt.md"
13+
prContextPushToPRBranchGuidanceFile = "pr_context_push_to_pr_branch_guidance.md"
1314
tempFolderPromptFile = "temp_folder_prompt.md"
1415
playwrightPromptFile = "playwright_prompt.md"
1516
qmdPromptFile = "qmd_prompt.md"

pkg/workflow/unified_prompt_step.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ func (c *Compiler) collectPromptSections(data *WorkflowData) []PromptSection {
272272
ShellCondition: shellCondition,
273273
EnvVars: envVars,
274274
})
275+
276+
// When push_to_pull_request_branch is configured, add guidance to prefer it over
277+
// create_pull_request when the workflow was triggered by a PR comment.
278+
if data.SafeOutputs != nil && data.SafeOutputs.PushToPullRequestBranch != nil {
279+
unifiedPromptLog.Print("Adding push-to-PR-branch tool preference guidance for PR comment context")
280+
sections = append(sections, PromptSection{
281+
Content: prContextPushToPRBranchGuidanceFile,
282+
IsFile: true,
283+
ShellCondition: shellCondition,
284+
EnvVars: envVars,
285+
})
286+
}
275287
}
276288

277289
return sections

0 commit comments

Comments
 (0)