-
Notifications
You must be signed in to change notification settings - Fork 430
safe-outputs: add merge-pull-request schema parity for samples and cross-repo targeting
#39767
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
Changes from 3 commits
ce54127
5f4c94d
40ee667
8975dd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,6 +238,61 @@ func TestPushToPullRequestBranchConfigTargetRepo(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // TestMergePullRequestConfigTargetRepo verifies that merge-pull-request | ||
| // correctly parses target-repo and allowed-repos fields. | ||
| func TestMergePullRequestConfigTargetRepo(t *testing.T) { | ||
| compiler := NewCompiler() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| configMap map[string]any | ||
| expectedRepo string | ||
| expectedRepos []string | ||
| expectedToken string | ||
| expectedTarget string | ||
| }{ | ||
| { | ||
| name: "target, target-repo and allowed-repos configured", | ||
| configMap: map[string]any{ | ||
| "merge-pull-request": map[string]any{ | ||
| "target": "*", | ||
| "target-repo": "githubnext/gh-aw-side-repo", | ||
| "allowed-repos": []any{"githubnext/gh-aw-side-repo"}, | ||
|
dsyme marked this conversation as resolved.
Outdated
dsyme marked this conversation as resolved.
Outdated
|
||
| "github-token": "${{ secrets.TEMP_USER_PAT }}", | ||
| }, | ||
| }, | ||
| expectedTarget: "*", | ||
| expectedRepo: "githubnext/gh-aw-side-repo", | ||
| expectedRepos: []string{"githubnext/gh-aw-side-repo"}, | ||
| expectedToken: "${{ secrets.TEMP_USER_PAT }}", | ||
| }, | ||
| { | ||
| name: "no cross-repo config", | ||
| configMap: map[string]any{ | ||
| "merge-pull-request": map[string]any{ | ||
| "required-labels": []any{"safe-to-merge"}, | ||
| }, | ||
| }, | ||
| expectedTarget: "", | ||
| expectedRepo: "", | ||
| expectedRepos: nil, | ||
| expectedToken: "", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| cfg := compiler.parseMergePullRequestConfig(tt.configMap) | ||
|
|
||
| require.NotNil(t, cfg, "config should not be nil") | ||
| assert.Equal(t, tt.expectedTarget, cfg.Target, "Target mismatch") | ||
| assert.Equal(t, tt.expectedRepo, cfg.TargetRepoSlug, "TargetRepoSlug mismatch") | ||
| assert.Equal(t, tt.expectedRepos, cfg.AllowedRepos, "AllowedRepos mismatch") | ||
| assert.Equal(t, tt.expectedToken, cfg.GitHubToken, "GitHubToken mismatch") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestUpdateIssueConfigGitHubToken verifies that update-issue correctly parses the github-token field. | ||
| func TestUpdateIssueConfigGitHubToken(t *testing.T) { | ||
| compiler := NewCompiler() | ||
|
|
@@ -464,6 +519,42 @@ func TestUpdateIssueGitHubTokenInHandlerConfig(t *testing.T) { | |
| assert.Contains(t, allowedRepos, "githubnext/gh-aw-side-repo", "allowed_repos should contain the repo") | ||
| } | ||
|
|
||
| // TestMergePullRequestCrossRepoInHandlerConfig verifies that target-repo and allowed-repos | ||
| // are included in the handler manager config JSON for merge-pull-request. | ||
| func TestMergePullRequestCrossRepoInHandlerConfig(t *testing.T) { | ||
| compiler := NewCompiler() | ||
|
|
||
| workflowData := &WorkflowData{ | ||
| Name: "Test", | ||
| SafeOutputs: &SafeOutputsConfig{ | ||
| MergePullRequest: &MergePullRequestConfig{ | ||
| BaseSafeOutputConfig: BaseSafeOutputConfig{ | ||
| GitHubToken: "${{ secrets.TEMP_USER_PAT }}", | ||
| }, | ||
| SafeOutputTargetConfig: SafeOutputTargetConfig{ | ||
| TargetRepoSlug: "githubnext/gh-aw-side-repo", | ||
| AllowedRepos: []string{"githubnext/gh-aw-side-repo"}, | ||
|
dsyme marked this conversation as resolved.
|
||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| var steps []string | ||
| compiler.addHandlerManagerConfigEnvVar(&steps, workflowData) | ||
|
|
||
| require.NotEmpty(t, steps) | ||
| handlerConfig := extractHandlerConfig(t, strings.Join(steps, "")) | ||
|
|
||
| mergePR, ok := handlerConfig["merge_pull_request"] | ||
| require.True(t, ok, "merge_pull_request config should be present") | ||
|
|
||
| assert.Equal(t, "githubnext/gh-aw-side-repo", mergePR["target-repo"], "target-repo should be in handler config") | ||
|
|
||
| allowedRepos, ok := mergePR["allowed_repos"] | ||
| require.True(t, ok, "allowed_repos should be present") | ||
| assert.Contains(t, allowedRepos, "githubnext/gh-aw-side-repo", "allowed_repos should contain the repo") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test coverage gap: 💡 Suggested fixAdd a sub-case that sets SafeOutputTargetConfig: SafeOutputTargetConfig{
Target: "*",
TargetRepoSlug: "githubnext/gh-aw-side-repo",
AllowedRepos: []string{"githubnext/gh-aw-side-repo"},
},
...
assert.Equal(t, "*", mergePR["target"], "target should be in handler config")Without this, the |
||
| } | ||
|
|
||
| // TestPushToPullRequestBranchCrossRepoInHandlerConfig verifies that target-repo and allowed-repos | ||
| // are included in the handler manager config JSON for push-to-pull-request-branch. | ||
| func TestPushToPullRequestBranchCrossRepoInHandlerConfig(t *testing.T) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.