Honor configured create_pull_request.base_branch in safe-output patch generation#26952
Honor configured create_pull_request.base_branch in safe-output patch generation#26952
create_pull_request.base_branch in safe-output patch generation#26952Conversation
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/120b88c0-60cb-4f0f-8c75-730a8a965c60 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ation Agent-Logs-Url: https://github.com/github/gh-aw/sessions/120b88c0-60cb-4f0f-8c75-730a8a965c60 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/120b88c0-60cb-4f0f-8c75-730a8a965c60 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
create_pull_request.base_branch in safe-output patch generation
There was a problem hiding this comment.
Pull request overview
Fixes safe-output patch generation for create_pull_request so it honors an explicitly configured create_pull_request.base_branch (instead of deriving the base branch from trigger context / repo defaults), preventing oversized patches in cross-repo workflows.
Changes:
- Update
createPullRequestHandlerbase branch resolution to preferconfig.create_pull_request.base_branch, falling back togetBaseBranch(repoParts)only when not configured. - Add a regression test covering a mismatch between trigger context base ref (
master) and configured base branch (main).
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/safe_outputs_handlers.cjs | Prefer configured base_branch for safe-output create_pull_request base branch selection. |
| actions/setup/js/safe_outputs_handlers.test.cjs | Add test ensuring configured base_branch overrides trigger-context base ref 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: 1
| // Get base branch for the resolved target repository. | ||
| // Prefer explicit safe-output config value when provided, otherwise fall back | ||
| // to dynamic resolution from trigger context/default branch. | ||
| const baseBranch = prConfig.base_branch || (await getBaseBranch(repoParts)); |
There was a problem hiding this comment.
prConfig.base_branch is now used directly to drive base branch selection, but it isn’t validated/normalized before use. If it’s mis-typed (non-string) or contains characters that normalizeBranchName() would change, downstream patch/bundle generation can fail with a generic "Failed to generate patch" message (because generateGitPatch() returns a different error shape on invalid baseBranch). Consider validating prConfig.base_branch up front (e.g., ensure it’s a non-empty string and equals its normalized form) and returning a clear error to the tool caller. This matches the stricter base branch validation pattern used in actions/setup/js/create_pull_request.cjs (e.g. around lines 364-377).
|
@copilot merge main, recompile, review all comments |
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/1665f7da-8f8d-4fee-980c-14e865a26507 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ut-patch-generator # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/1665f7da-8f8d-4fee-980c-14e865a26507 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Merged main and recompiled, then reviewed the comments and applied the follow-up validation for Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
create_pull_request.base_branch in safe-output patch generationcreate_pull_request.base_branch in safe-output patch generation
| // Get base branch for the resolved target repository. | ||
| // Prefer explicit safe-output config value when provided, otherwise fall back | ||
| // to dynamic resolution from trigger context/default branch. | ||
| let baseBranch = null; | ||
| if (prConfig.base_branch !== undefined && prConfig.base_branch !== null) { | ||
| if (typeof prConfig.base_branch !== "string") { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: "text", | ||
| text: JSON.stringify({ | ||
| result: "error", | ||
| error: `Invalid create_pull_request.base_branch: expected string, got ${typeof prConfig.base_branch}`, | ||
| }), | ||
| }, | ||
| ], | ||
| isError: true, | ||
| }; | ||
| } | ||
|
|
||
| const normalizedConfigBase = normalizeBranchName(prConfig.base_branch); | ||
| if (!normalizedConfigBase) { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: "text", | ||
| text: JSON.stringify({ | ||
| result: "error", | ||
| error: `Invalid create_pull_request.base_branch: sanitization resulted in empty string (original: "${prConfig.base_branch}")`, | ||
| }), | ||
| }, | ||
| ], | ||
| isError: true, | ||
| }; | ||
| } | ||
| if (prConfig.base_branch !== normalizedConfigBase) { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: "text", | ||
| text: JSON.stringify({ | ||
| result: "error", | ||
| error: `Invalid create_pull_request.base_branch: contains invalid characters (original: "${prConfig.base_branch}", normalized: "${normalizedConfigBase}")`, | ||
| }), | ||
| }, | ||
| ], | ||
| isError: true, | ||
| }; | ||
| } | ||
| baseBranch = prConfig.base_branch; | ||
| } else { | ||
| baseBranch = await getBaseBranch(repoParts); | ||
| } |
There was a problem hiding this comment.
@copilot remove. base_branch is not required if allowed_branches is specified.
There was a problem hiding this comment.
Removed the strict base_branch validation block and related tests as requested; behavior now keeps configured-base precedence without requiring that validation path. Addressed in 20b9cef.
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/0b8eea5b-25b5-4bba-8196-d819751c99b7 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
create_pull_request.base_branch in safe-output patch generationcreate_pull_request.base_branch in safe-output patch generation
The safe-output
create_pull_requestpatch path was resolving its base branch from trigger context/default branch (GITHUB_BASE_REF/repo default) instead of the configuredbase_branch. In cross-repo workflows where trigger/default branch differs from target repo base, this could produce oversized patches with unrelated commits.Base branch resolution fix (
safe_outputs_handlers.cjs)createPullRequestHandlerto prioritize explicit safe-output config:create_pull_request.base_branchis now used first.getBaseBranch(repoParts)) is only used as fallback.Regression coverage (
safe_outputs_handlers.test.cjs)masterbase_branch=mainmain> [!WARNING]
>
>