Skip to content

Commit bff468b

Browse files
BagToadCopilot
andcommitted
fix(pr create): wire up @copilot assignee replacement and [bot] suffix
Two bugs introduced in cli#13009 found during acceptance testing: 1. `pr create --assignee @copilot` sent the literal `@copilot` to the API because NewIssueState only ran MeReplacer on assignees, not CopilotReplacer. Fixed by switching to SpecialAssigneeReplacer (which handles both @me and @copilot) like issue create already does. 2. The replaceActorsForAssignable mutation requires the [bot] suffix on bot actor logins (e.g. `copilot-swe-agent[bot]`), unlike requestReviewsByLogin which has a separate botLogins field. Added the suffix in ReplaceActorsForAssignableByLogin for CopilotAssigneeLogin. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6a68ebc commit bff468b

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

api/queries_pr.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,12 @@ func ReplaceActorsForAssignableByLogin(client *Client, repo ghrepo.Interface, as
599599

600600
actorLogins := make([]githubv4.String, len(logins))
601601
for i, l := range logins {
602+
// The replaceActorsForAssignable mutation requires the [bot] suffix
603+
// for bot actor logins (e.g. "copilot-swe-agent[bot]"), unlike
604+
// requestReviewsByLogin which has a separate botLogins field.
605+
if l == CopilotAssigneeLogin {
606+
l = l + "[bot]"
607+
}
602608
actorLogins[i] = githubv4.String(l)
603609
}
604610

pkg/cmd/issue/create/create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ func Test_createRun(t *testing.T) {
548548
{ "data": { "replaceActorsForAssignable": { "__typename": "" } } }
549549
`, func(inputs map[string]interface{}) {
550550
assert.Equal(t, "ISSUEID", inputs["assignableId"])
551-
assert.Equal(t, []interface{}{"copilot-swe-agent", "MonaLisa"}, inputs["actorLogins"])
551+
assert.Equal(t, []interface{}{"copilot-swe-agent[bot]", "MonaLisa"}, inputs["actorLogins"])
552552
}))
553553
},
554554
wantsStdout: "https://github.com/OWNER/REPO/issues/12\n",
@@ -1161,7 +1161,7 @@ func TestIssueCreate_AtCopilotAssignee(t *testing.T) {
11611161
{ "data": { "replaceActorsForAssignable": { "__typename": "" } } }
11621162
`, func(inputs map[string]interface{}) {
11631163
assert.Equal(t, "NEWISSUEID", inputs["assignableId"])
1164-
assert.Equal(t, []interface{}{"copilot-swe-agent"}, inputs["actorLogins"])
1164+
assert.Equal(t, []interface{}{"copilot-swe-agent[bot]"}, inputs["actorLogins"])
11651165
}))
11661166

11671167
output, err := runCommand(http, true, `-a @copilot -t hello -b "cash rules everything around me"`, nil)

pkg/cmd/pr/create/create.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func createRun(opts *CreateOptions) error {
424424
assigneeSearchFunc = shared.RepoAssigneeSearchFunc(client, ctx.PRRefs.BaseRepo())
425425
}
426426

427-
state, err := NewIssueState(*ctx, *opts)
427+
state, err := NewIssueState(*ctx, *opts, issueFeatures.ApiActorsSupported)
428428
if err != nil {
429429
return err
430430
}
@@ -672,14 +672,14 @@ func initDefaultTitleBody(ctx CreateContext, state *shared.IssueMetadataState, u
672672
return nil
673673
}
674674

675-
func NewIssueState(ctx CreateContext, opts CreateOptions) (*shared.IssueMetadataState, error) {
675+
func NewIssueState(ctx CreateContext, opts CreateOptions, apiActorsSupported bool) (*shared.IssueMetadataState, error) {
676676
var milestoneTitles []string
677677
if opts.Milestone != "" {
678678
milestoneTitles = []string{opts.Milestone}
679679
}
680680

681-
meReplacer := shared.NewMeReplacer(ctx.Client, ctx.PRRefs.BaseRepo().RepoHost())
682-
assignees, err := meReplacer.ReplaceSlice(opts.Assignees)
681+
assigneeReplacer := shared.NewSpecialAssigneeReplacer(ctx.Client, ctx.PRRefs.BaseRepo().RepoHost(), apiActorsSupported, !opts.WebMode)
682+
assignees, err := assigneeReplacer.ReplaceSlice(opts.Assignees)
683683
if err != nil {
684684
return nil, err
685685
}

0 commit comments

Comments
 (0)