Add base-branch field for cross-repo PRs targeting non-default branches#15089
Add base-branch field for cross-repo PRs targeting non-default branches#15089
base-branch field for cross-repo PRs targeting non-default branches#15089Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
base-branch field for cross-repo PRs targeting non-default branches
|
@copilot Merge main and recompile |
There was a problem hiding this comment.
Pull request overview
Adds support for configuring the base branch used by the create-pull-request safe output, enabling cross-repo PR creation targeting non-default branches while keeping the existing ${{ github.ref_name }} default.
Changes:
- Added
base-branchtoCreatePullRequestsConfigand propagate it into the create PR job env (GH_AW_BASE_BRANCH) and handler-manager config (base_branch). - Extended the workflow JSON schema to accept the new
base-branchfield. - Added unit + integration coverage to validate default vs custom base branch compilation.
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/create_pull_request_base_branch_integration_test.go | New integration tests that compile workflows and assert base_branch output for custom/default/slash-containing branches. |
| pkg/workflow/create_pull_request.go | Adds BaseBranch config field and uses it to set GH_AW_BASE_BRANCH, falling back to ${{ github.ref_name }}. |
| pkg/workflow/compiler_safe_outputs_config_test.go | Adds unit test verifying handler-manager config JSON includes the expected base_branch. |
| pkg/workflow/compiler_safe_outputs_config.go | Updates create_pull_request handler config builder to emit custom base_branch or default ${{ github.ref_name }}. |
| pkg/parser/schemas/main_workflow_schema.json | Adds base-branch to the create-pull-request schema definition. |
| docs/src/content/docs/reference/frontmatter-full.md | Documents the new base-branch option under safe-outputs.create-pull-request. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for _, step := range steps { | ||
| if strings.Contains(step, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG") { | ||
| parts := strings.Split(step, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG: ") | ||
| if len(parts) == 2 { | ||
| jsonStr := strings.TrimSpace(parts[1]) | ||
| jsonStr = strings.Trim(jsonStr, "\"") | ||
| jsonStr = strings.ReplaceAll(jsonStr, "\\\"", "\"") | ||
|
|
||
| var config map[string]map[string]any | ||
| err := json.Unmarshal([]byte(jsonStr), &config) | ||
| require.NoError(t, err, "Config JSON should be valid") | ||
|
|
||
| prConfig, ok := config["create_pull_request"] | ||
| require.True(t, ok, "create_pull_request config should exist") | ||
|
|
||
| baseBranch, ok := prConfig["base_branch"] | ||
| require.True(t, ok, "base_branch should be in config") | ||
|
|
||
| assert.Equal(t, tt.expectedBaseBranch, baseBranch, "base_branch should match expected value") | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
In TestCreatePullRequestBaseBranch, the JSON extraction loop doesn’t assert that it actually found/parses the GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG line. If the env var generation regresses (or the string format changes), the test can pass without validating anything. Track a found boolean (or extract once with SplitN) and require.True(t, found, ...) after the loop, and consider failing if len(parts) != 2 to avoid silent success.
| for _, step := range steps { | |
| if strings.Contains(step, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG") { | |
| parts := strings.Split(step, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG: ") | |
| if len(parts) == 2 { | |
| jsonStr := strings.TrimSpace(parts[1]) | |
| jsonStr = strings.Trim(jsonStr, "\"") | |
| jsonStr = strings.ReplaceAll(jsonStr, "\\\"", "\"") | |
| var config map[string]map[string]any | |
| err := json.Unmarshal([]byte(jsonStr), &config) | |
| require.NoError(t, err, "Config JSON should be valid") | |
| prConfig, ok := config["create_pull_request"] | |
| require.True(t, ok, "create_pull_request config should exist") | |
| baseBranch, ok := prConfig["base_branch"] | |
| require.True(t, ok, "base_branch should be in config") | |
| assert.Equal(t, tt.expectedBaseBranch, baseBranch, "base_branch should match expected value") | |
| } | |
| } | |
| } | |
| found := false | |
| for _, step := range steps { | |
| if strings.Contains(step, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG") { | |
| parts := strings.SplitN(step, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG: ", 2) | |
| require.Len(t, parts, 2, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG line should contain key and value") | |
| found = true | |
| jsonStr := strings.TrimSpace(parts[1]) | |
| jsonStr = strings.Trim(jsonStr, "\"") | |
| jsonStr = strings.ReplaceAll(jsonStr, "\\\"", "\"") | |
| var config map[string]map[string]any | |
| err := json.Unmarshal([]byte(jsonStr), &config) | |
| require.NoError(t, err, "Config JSON should be valid") | |
| prConfig, ok := config["create_pull_request"] | |
| require.True(t, ok, "create_pull_request config should exist") | |
| baseBranch, ok := prConfig["base_branch"] | |
| require.True(t, ok, "base_branch should be in config") | |
| assert.Equal(t, tt.expectedBaseBranch, baseBranch, "base_branch should match expected value") | |
| } | |
| } | |
| require.True(t, found, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG should be present in steps") |
Add documentation for the new base-branch configuration option in the create-pull-request safe output. This field allows workflows to specify which branch a pull request should target, particularly useful for cross-repository workflows targeting non-default branches. Changes: - Add base-branch field to create-pull-request YAML example - Document default behavior (defaults to github.ref_name) - Include use case example for cross-repo PR targeting vnext branch Related: #15089 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add glossary entry for the base-branch configuration field that was introduced in PR #15089. This field allows specifying target branches for cross-repository pull requests, particularly useful for targeting non-default branches like vnext or release branches.
Implementation Complete ✅
Successfully merged main branch and recompiled all workflows with both
base-branchandfooterfields working together.Changes Made
Merge Conflicts Resolved:
BaseBranchandFooterfields inCreatePullRequestsConfigstructValidation:
Usage Example
Both fields can now be used together:
Compiles to:
{ "create_pull_request": { "base_branch": "vnext", "footer": false, "target-repo": "microsoft/vscode-docs", "draft": true } }Backward Compatibility
Both fields maintain backward compatibility:
base-branchdefaults to${{ github.ref_name }}when not specifiedfooterdefaults totruewhen not specifiedOriginal prompt
base-branchfield for cross-repo PRs targeting non-default branches #15075💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.