-
Notifications
You must be signed in to change notification settings - Fork 141
Add base-branch field for cross-repo PRs targeting non-default branches
#15089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3efce1d
Initial plan
Copilot af3876a
Add base-branch field for create-pull-request safe output
Copilot 9a0c21e
Update documentation with base-branch field
Copilot 729952f
Merge remote-tracking branch 'origin/main' into copilot/add-base-bran…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
pkg/workflow/create_pull_request_base_branch_integration_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| //go:build integration | ||
|
|
||
| package workflow | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestCreatePullRequestWithCustomBaseBranch tests end-to-end workflow compilation with custom base-branch | ||
| func TestCreatePullRequestWithCustomBaseBranch(t *testing.T) { | ||
| tmpDir, err := os.MkdirTemp("", "base-branch-test") | ||
| if err != nil { | ||
| t.Fatalf("Failed to create temp dir: %v", err) | ||
| } | ||
| defer os.RemoveAll(tmpDir) | ||
|
|
||
| // Create test workflow with custom base-branch | ||
| workflowContent := `--- | ||
| on: push | ||
| permissions: | ||
| contents: read | ||
| actions: read | ||
| issues: read | ||
| pull-requests: read | ||
| engine: copilot | ||
| safe-outputs: | ||
| create-pull-request: | ||
| target-repo: "microsoft/vscode-docs" | ||
| base-branch: vnext | ||
| draft: true | ||
| --- | ||
|
|
||
| # Test Workflow | ||
|
|
||
| Create a pull request targeting vnext branch in cross-repo. | ||
| ` | ||
|
|
||
| workflowPath := filepath.Join(tmpDir, "test-workflow.md") | ||
| if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil { | ||
| t.Fatalf("Failed to write workflow file: %v", err) | ||
| } | ||
|
|
||
| // Compile the workflow | ||
| compiler := NewCompiler() | ||
| if err := compiler.CompileWorkflow(workflowPath); err != nil { | ||
| t.Fatalf("Failed to compile workflow: %v", err) | ||
| } | ||
|
|
||
| // Read the compiled output | ||
| outputFile := filepath.Join(tmpDir, "test-workflow.lock.yml") | ||
| compiledBytes, err := os.ReadFile(outputFile) | ||
| if err != nil { | ||
| t.Fatalf("Failed to read compiled output: %v", err) | ||
| } | ||
|
|
||
| compiledContent := string(compiledBytes) | ||
|
|
||
| // Verify GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG contains base_branch set to "vnext" | ||
| // The JSON is escaped in YAML, so we need to look for the escaped version | ||
| if !strings.Contains(compiledContent, `\"base_branch\":\"vnext\"`) { | ||
| t.Error("Expected handler config to contain base_branch set to vnext in compiled workflow") | ||
| } | ||
|
|
||
| // Verify it does NOT contain the default github.ref_name expression | ||
| if strings.Contains(compiledContent, `\"base_branch\":\"${{ github.ref_name }}\"`) { | ||
| t.Error("Did not expect handler config to use github.ref_name when base-branch is explicitly set") | ||
| } | ||
| } | ||
|
|
||
| // TestCreatePullRequestWithDefaultBaseBranch tests workflow compilation with default base-branch | ||
| func TestCreatePullRequestWithDefaultBaseBranch(t *testing.T) { | ||
| tmpDir, err := os.MkdirTemp("", "default-base-branch-test") | ||
| if err != nil { | ||
| t.Fatalf("Failed to create temp dir: %v", err) | ||
| } | ||
| defer os.RemoveAll(tmpDir) | ||
|
|
||
| // Create test workflow without base-branch field | ||
| workflowContent := `--- | ||
| on: push | ||
| permissions: | ||
| contents: read | ||
| actions: read | ||
| issues: read | ||
| pull-requests: read | ||
| engine: copilot | ||
| safe-outputs: | ||
| create-pull-request: | ||
| draft: true | ||
| --- | ||
|
|
||
| # Test Workflow | ||
|
|
||
| Create a pull request with default base branch. | ||
| ` | ||
|
|
||
| workflowPath := filepath.Join(tmpDir, "test-default.md") | ||
| if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil { | ||
| t.Fatalf("Failed to write workflow file: %v", err) | ||
| } | ||
|
|
||
| // Compile the workflow | ||
| compiler := NewCompiler() | ||
| if err := compiler.CompileWorkflow(workflowPath); err != nil { | ||
| t.Fatalf("Failed to compile workflow: %v", err) | ||
| } | ||
|
|
||
| // Read the compiled output | ||
| outputFile := filepath.Join(tmpDir, "test-default.lock.yml") | ||
| compiledBytes, err := os.ReadFile(outputFile) | ||
| if err != nil { | ||
| t.Fatalf("Failed to read compiled output: %v", err) | ||
| } | ||
|
|
||
| compiledContent := string(compiledBytes) | ||
|
|
||
| // Verify GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG uses github.ref_name by default | ||
| // The JSON is escaped in YAML, so we need to look for the escaped version | ||
| if !strings.Contains(compiledContent, `\"base_branch\":\"${{ github.ref_name }}\"`) { | ||
| t.Error("Expected handler config to use github.ref_name when base-branch is not specified") | ||
| } | ||
| } | ||
|
|
||
| // TestCreatePullRequestWithBranchSlash tests workflow compilation with branch containing slash | ||
| func TestCreatePullRequestWithBranchSlash(t *testing.T) { | ||
| tmpDir, err := os.MkdirTemp("", "branch-slash-test") | ||
| if err != nil { | ||
| t.Fatalf("Failed to create temp dir: %v", err) | ||
| } | ||
| defer os.RemoveAll(tmpDir) | ||
|
|
||
| // Create test workflow with base-branch containing slash | ||
| workflowContent := `--- | ||
| on: push | ||
| permissions: | ||
| contents: read | ||
| actions: read | ||
| issues: read | ||
| pull-requests: read | ||
| engine: copilot | ||
| safe-outputs: | ||
| create-pull-request: | ||
| base-branch: release/v1.0 | ||
| draft: true | ||
| --- | ||
|
|
||
| # Test Workflow | ||
|
|
||
| Create a pull request targeting release/v1.0 branch. | ||
| ` | ||
|
|
||
| workflowPath := filepath.Join(tmpDir, "test-slash.md") | ||
| if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil { | ||
| t.Fatalf("Failed to write workflow file: %v", err) | ||
| } | ||
|
|
||
| // Compile the workflow | ||
| compiler := NewCompiler() | ||
| if err := compiler.CompileWorkflow(workflowPath); err != nil { | ||
| t.Fatalf("Failed to compile workflow: %v", err) | ||
| } | ||
|
|
||
| // Read the compiled output | ||
| outputFile := filepath.Join(tmpDir, "test-slash.lock.yml") | ||
| compiledBytes, err := os.ReadFile(outputFile) | ||
| if err != nil { | ||
| t.Fatalf("Failed to read compiled output: %v", err) | ||
| } | ||
|
|
||
| compiledContent := string(compiledBytes) | ||
|
|
||
| // Verify GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG contains base_branch set to "release/v1.0" | ||
| // The JSON is escaped in YAML, so we need to look for the escaped version | ||
| if !strings.Contains(compiledContent, `\"base_branch\":\"release/v1.0\"`) { | ||
| t.Error("Expected handler config to contain base_branch set to release/v1.0 in compiled workflow") | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
foundboolean (or extract once with SplitN) andrequire.True(t, found, ...)after the loop, and consider failing iflen(parts) != 2to avoid silent success.