Skip to content

Improve base branch resolution for cross-repo PRs - #18614

Merged
dsyme merged 8 commits into
mainfrom
cr2
Feb 27, 2026
Merged

Improve base branch resolution for cross-repo PRs#18614
dsyme merged 8 commits into
mainfrom
cr2

Conversation

@dsyme

Copy link
Copy Markdown
Collaborator

For cross-repo PRs, getBaseBranch() needed to become dependent on the target repo

This does structural work to get that to happen

@dsyme
dsyme marked this pull request as ready for review February 27, 2026 01:53
CopilotAI review requested due to automatic review settings February 27, 2026 01:53

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates base-branch resolution so cross-repo PR operations resolve the base branch against the configured target repository (not the workflow repo), and threads that base branch into patch generation.

Changes:

  • Add an optional targetRepo parameter to getBaseBranch() so issue_comment PR base lookups can query the correct repository.
  • Make generateGitPatch() take an explicit baseBranch argument and update callers/tests accordingly.
  • Resolve the configured target repo (via repo_helpers) in safe-output handlers and other entrypoints before calling getBaseBranch().

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
actions/setup/js/safe_outputs_handlers.test.cjsAdds a mocked global.context needed by target-repo resolution in handler tests.
actions/setup/js/safe_outputs_handlers.cjsResolves target repo before calling getBaseBranch() and passes resolved base branch into generateGitPatch().
actions/setup/js/push_to_pull_request_branch.cjsParses configured target repo and passes it into getBaseBranch() for cross-repo correctness.
actions/setup/js/git_patch_integration.test.cjsUpdates integration tests to pass an explicit base branch into generateGitPatch().
actions/setup/js/get_base_branch.test.cjsAdds coverage for the new optional targetRepo parameter.
actions/setup/js/get_base_branch.cjsImplements targetRepo support for issue_comment PR base-branch API lookup.
actions/setup/js/generate_git_patch.test.cjsUpdates tests for the new generateGitPatch(branch, baseBranch, options) signature.
actions/setup/js/generate_git_patch.cjsChanges patch generation to rely on a caller-provided base branch (no internal getBaseBranch() lookup).
actions/setup/js/create_pull_request.cjsParses configured target repo and passes it into getBaseBranch() for cross-repo correctness.
actions/setup/js/create_agent_session.cjsParses configured target repo and passes it into getBaseBranch() for cross-repo correctness.
Comments suppressed due to low confidence (1)

actions/setup/js/safe_outputs_handlers.cjs:199

  • resolveTargetRepoConfig() ultimately falls back to context.repo (repo_helpers.getDefaultTargetRepo). In the MCP server entrypoint (safe-outputs-mcp-server.cjs), only global.core is shimmed (shim.cjs) and global.context is not set, so invoking create_pull_request via the MCP server can throw a ReferenceError when no target-repo/GH_AW_TARGET_REPO_SLUG is configured. Consider adding a local fallback here (e.g., prefer prConfig["target-repo"], then process.env.GH_AW_TARGET_REPO_SLUG, then process.env.GITHUB_REPOSITORY) and/or explicitly error with ERR_CONFIG when none are available instead of relying on context.
 // Resolve target repo for base branch resolution (cross-repo scenarios)
const prConfig = config.create_pull_request || {};
const { defaultTargetRepo } = resolveTargetRepoConfig(prConfig);
const targetRepoParts = parseRepoSlug(defaultTargetRepo);
const baseBranch = await getBaseBranch(targetRepoParts);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadactions/setup/js/safe_outputs_handlers.cjs Outdated
Comment threadactions/setup/js/generate_git_patch.cjs

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadactions/setup/js/generate_git_patch.cjs Outdated
Comment threadactions/setup/js/create_pull_request.cjs Outdated
@dsyme
dsyme merged commit 4f14974 into mainFeb 27, 2026
46 checks passed
@dsyme
dsyme deleted the cr2 branch February 27, 2026 02:33
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@dsyme