Skip to content

Commit 08c7a4c

Browse files
BagToadCopilot
andcommitted
Replace @copilot with Copilot reviewer login in gh pr create
Wire CopilotReviewerReplacer into NewIssueState so that `gh pr create --reviewer @copilot` correctly resolves to the copilot-pull-request-reviewer bot login, matching the behavior already implemented in gh pr edit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 49f1bd8 commit 08c7a4c

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

pkg/cmd/pr/create/create.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,12 @@ func NewIssueState(ctx CreateContext, opts CreateOptions) (*shared.IssueMetadata
680680
return nil, err
681681
}
682682

683+
copilotReplacer := shared.NewCopilotReviewerReplacer()
684+
reviewers := copilotReplacer.ReplaceSlice(opts.Reviewers)
685+
683686
state := &shared.IssueMetadataState{
684687
Type: shared.PRMetadata,
685-
Reviewers: opts.Reviewers,
688+
Reviewers: reviewers,
686689
Assignees: assignees,
687690
Labels: opts.Labels,
688691
ProjectTitles: opts.Projects,

pkg/cmd/pr/create/create_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,42 @@ func Test_createRun(t *testing.T) {
15231523
expectedOut: "https://github.com/OWNER/REPO/pull/12\n",
15241524
expectedErrOut: "",
15251525
},
1526+
{
1527+
name: "@copilot reviewer resolves to bot login",
1528+
setup: func(opts *CreateOptions, t *testing.T) func() {
1529+
opts.TitleProvided = true
1530+
opts.BodyProvided = true
1531+
opts.Title = "my title"
1532+
opts.Body = "my body"
1533+
opts.Reviewers = []string{"hubot", "@copilot"}
1534+
opts.HeadBranch = "feature"
1535+
return func() {}
1536+
},
1537+
httpStubs: func(reg *httpmock.Registry, t *testing.T) {
1538+
reg.Register(
1539+
httpmock.GraphQL(`mutation PullRequestCreate\b`),
1540+
httpmock.GraphQLMutation(`
1541+
{ "data": { "createPullRequest": { "pullRequest": {
1542+
"URL": "https://github.com/OWNER/REPO/pull/12",
1543+
"id": "NEWPULLID"
1544+
} } } }`,
1545+
func(input map[string]interface{}) {}))
1546+
reg.Register(
1547+
httpmock.GraphQL(`mutation RequestReviewsByLogin\b`),
1548+
httpmock.GraphQLMutation(`
1549+
{ "data": { "requestReviewsByLogin": {
1550+
"clientMutationId": ""
1551+
} } }
1552+
`, func(inputs map[string]interface{}) {
1553+
assert.Equal(t, "NEWPULLID", inputs["pullRequestId"])
1554+
assert.Equal(t, []interface{}{"hubot"}, inputs["userLogins"])
1555+
assert.Equal(t, []interface{}{"copilot-pull-request-reviewer[bot]"}, inputs["botLogins"])
1556+
assert.Equal(t, true, inputs["union"])
1557+
}))
1558+
},
1559+
expectedOut: "https://github.com/OWNER/REPO/pull/12\n",
1560+
expectedErrOut: "",
1561+
},
15261562
}
15271563
for _, tt := range tests {
15281564
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)