Fix: Use target repository for git operations in create-pull-request#15501
Fix: Use target repository for git operations in create-pull-request#15501
Conversation
- Update buildCheckoutRepository to accept and use targetRepoSlug parameter - Update generateGitConfigurationStepsWithToken to use target repo for REPO_NAME - Fix buildSharedPRCheckoutSteps in consolidated safe-outputs job to use target-repo - Add integration tests for cross-repo and same-repo checkout scenarios Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes a critical bug where create-pull-request's target-repo configuration was ignored by git operations (checkout, fetch, push) in the safe_outputs job. The PR ensures that when a target repository is specified, both the actions/checkout step and git remote configuration use the target repository instead of the source repository.
Changes:
- Modified
buildCheckoutRepositoryto accept atargetRepoSlugparameter and set therepository:field on actions/checkout when specified - Modified
generateGitConfigurationStepsWithTokento accept atargetRepoSlugparameter and configureREPO_NAMEto the target repository - Updated
buildSharedPRCheckoutStepsto extract and pass the target-repo from create-pull-request config to checkout and git configuration steps - Added integration tests to verify cross-repo and same-repo checkout behavior
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/yaml_generation.go |
Added targetRepoSlug parameter to generateGitConfigurationStepsWithToken with correct priority logic (targetRepoSlug > trialLogicalRepoSlug > default) |
pkg/workflow/push_to_pull_request_branch.go |
Added targetRepoSlug parameter to buildCheckoutRepository but contains priority logic bug where trialLogicalRepoSlug can override targetRepoSlug |
pkg/workflow/publish_assets.go |
Updated call to buildCheckoutRepository to pass empty string for target repo (no target repo for upload assets) |
pkg/workflow/create_pull_request.go |
Updated to pass TargetRepoSlug from config to both buildCheckoutRepository and generateGitConfigurationStepsWithToken |
pkg/workflow/compiler_safe_outputs_steps.go |
Updated buildSharedPRCheckoutSteps to extract target-repo and configure both checkout and git config correctly with proper priority logic |
pkg/workflow/create_pull_request_cross_repo_integration_test.go |
Added integration tests for cross-repo and same-repo checkout scenarios |
Comments suppressed due to low confidence (1)
pkg/workflow/push_to_pull_request_branch.go:39
- The priority logic for determining effectiveTargetRepo is inverted. When both targetRepoSlug and trialLogicalRepoSlug are set, the code gives priority to trialLogicalRepoSlug instead of targetRepoSlug as documented.
The current code:
- Sets effectiveTargetRepo = targetRepoSlug
- Then overwrites it with trialLogicalRepoSlug if in trial mode
This means trialLogicalRepoSlug takes priority over targetRepoSlug, which contradicts the comment on line 35 that states "Priority: targetRepoSlug > trialLogicalRepoSlug > default".
The correct logic should check if targetRepoSlug is empty before using trialLogicalRepoSlug.
effectiveTargetRepo := targetRepoSlug
if c.trialMode && c.trialLogicalRepoSlug != "" {
effectiveTargetRepo = c.trialLogicalRepoSlug
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Add token for trial mode or when checking out a different repository | ||
| if c.trialMode || targetRepoSlug != "" { |
There was a problem hiding this comment.
The condition for adding a token should consider effectiveTargetRepo instead of just targetRepoSlug. If trialLogicalRepoSlug is set (in trial mode), a token is already included, but the current logic may not include a token when only targetRepoSlug is set without trial mode.
However, after the priority bug is fixed, this condition should be: if effectiveTargetRepo != "" to properly handle all cases where we're checking out a different repository.
This issue also appears on line 36 of the same file.
| // Add token for trial mode or when checking out a different repository | |
| if c.trialMode || targetRepoSlug != "" { | |
| // Add token when checking out a different repository | |
| if effectiveTargetRepo != "" { |
When
create-pull-requestspecifiestarget-repo, git operations (checkout, fetch, push) incorrectly used the source repository. The target repo was only used for the PR API call, causing failures when the base branch exists only in the target repo (e.g.,vnextbranch in cross-repo PRs).Changes
Compiler updates:
buildCheckoutRepository: AddedtargetRepoSlugparameter, setsrepository:on actions/checkout when specifiedgenerateGitConfigurationStepsWithToken: AddedtargetRepoSlugparameter, setsREPO_NAMEenv var to target repo instead of${{ github.repository }}buildSharedPRCheckoutSteps: Extracts target-repo from create-pull-request config and passes to checkout/git config stepsbuildCreateOutputPullRequestJob: Passes target-repo to checkout and git config generationTesting:
Example
Before (wrong):
After (correct):
Original prompt
create-pull-requesttarget-repois ignored by git operations in safe_outputs job #15500💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.