diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 631e69430..1f2ce190a 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -680,9 +680,12 @@ func NewIssueState(ctx CreateContext, opts CreateOptions) (*shared.IssueMetadata return nil, err } + copilotReplacer := shared.NewCopilotReviewerReplacer() + reviewers := copilotReplacer.ReplaceSlice(opts.Reviewers) + state := &shared.IssueMetadataState{ Type: shared.PRMetadata, - Reviewers: opts.Reviewers, + Reviewers: reviewers, Assignees: assignees, Labels: opts.Labels, ProjectTitles: opts.Projects, diff --git a/pkg/cmd/pr/create/create_test.go b/pkg/cmd/pr/create/create_test.go index 428aca650..d7c7fff87 100644 --- a/pkg/cmd/pr/create/create_test.go +++ b/pkg/cmd/pr/create/create_test.go @@ -1523,6 +1523,42 @@ func Test_createRun(t *testing.T) { expectedOut: "https://github.com/OWNER/REPO/pull/12\n", expectedErrOut: "", }, + { + name: "@copilot reviewer resolves to bot login", + setup: func(opts *CreateOptions, t *testing.T) func() { + opts.TitleProvided = true + opts.BodyProvided = true + opts.Title = "my title" + opts.Body = "my body" + opts.Reviewers = []string{"hubot", "@copilot"} + opts.HeadBranch = "feature" + return func() {} + }, + httpStubs: func(reg *httpmock.Registry, t *testing.T) { + reg.Register( + httpmock.GraphQL(`mutation PullRequestCreate\b`), + httpmock.GraphQLMutation(` + { "data": { "createPullRequest": { "pullRequest": { + "URL": "https://github.com/OWNER/REPO/pull/12", + "id": "NEWPULLID" + } } } }`, + func(input map[string]interface{}) {})) + reg.Register( + httpmock.GraphQL(`mutation RequestReviewsByLogin\b`), + httpmock.GraphQLMutation(` + { "data": { "requestReviewsByLogin": { + "clientMutationId": "" + } } } + `, func(inputs map[string]interface{}) { + assert.Equal(t, "NEWPULLID", inputs["pullRequestId"]) + assert.Equal(t, []interface{}{"hubot"}, inputs["userLogins"]) + assert.Equal(t, []interface{}{"copilot-pull-request-reviewer[bot]"}, inputs["botLogins"]) + assert.Equal(t, true, inputs["union"]) + })) + }, + expectedOut: "https://github.com/OWNER/REPO/pull/12\n", + expectedErrOut: "", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {