Skip to content

Improve base branch resolution for cross-repo PRs#18614

Merged
dsyme merged 8 commits intomainfrom
cr2
Feb 27, 2026
Merged

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

Conversation

@dsyme
Copy link
Contributor

@dsyme dsyme commented Feb 27, 2026

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
Copilot AI review requested due to automatic review settings February 27, 2026 01:53
Copy link
Contributor

Copilot AI left a comment

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
File Description
actions/setup/js/safe_outputs_handlers.test.cjs Adds a mocked global.context needed by target-repo resolution in handler tests.
actions/setup/js/safe_outputs_handlers.cjs Resolves target repo before calling getBaseBranch() and passes resolved base branch into generateGitPatch().
actions/setup/js/push_to_pull_request_branch.cjs Parses configured target repo and passes it into getBaseBranch() for cross-repo correctness.
actions/setup/js/git_patch_integration.test.cjs Updates integration tests to pass an explicit base branch into generateGitPatch().
actions/setup/js/get_base_branch.test.cjs Adds coverage for the new optional targetRepo parameter.
actions/setup/js/get_base_branch.cjs Implements targetRepo support for issue_comment PR base-branch API lookup.
actions/setup/js/generate_git_patch.test.cjs Updates tests for the new generateGitPatch(branch, baseBranch, options) signature.
actions/setup/js/generate_git_patch.cjs Changes patch generation to rely on a caller-provided base branch (no internal getBaseBranch() lookup).
actions/setup/js/create_pull_request.cjs Parses configured target repo and passes it into getBaseBranch() for cross-repo correctness.
actions/setup/js/create_agent_session.cjs Parses 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.

Copy link
Contributor

Copilot AI left a comment

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.

@dsyme dsyme merged commit 4f14974 into main Feb 27, 2026
46 checks passed
@dsyme dsyme deleted the cr2 branch February 27, 2026 02:33
Sign up for free to 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