Skip to content

Commit e0d7ad7

Browse files
authored
Merge pull request #10992 from cli/kw/gh-cli-epic-900-actors-are-assignable
Copilot is assignable to issues and pull requests with `issue edit` and `pr edit`
2 parents 17af24e + 0788a01 commit e0d7ad7

18 files changed

+1018
-150
lines changed

api/queries_issue.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Issue struct {
3838
Comments Comments
3939
Author Author
4040
Assignees Assignees
41+
AssignedActors AssignedActors
4142
Labels Labels
4243
ProjectCards ProjectCards
4344
ProjectItems ProjectItems
@@ -91,6 +92,61 @@ func (a Assignees) Logins() []string {
9192
return logins
9293
}
9394

95+
type AssignedActors struct {
96+
Nodes []Actor
97+
TotalCount int
98+
}
99+
100+
func (a AssignedActors) Logins() []string {
101+
logins := make([]string, len(a.Nodes))
102+
for i, a := range a.Nodes {
103+
logins[i] = a.Login
104+
}
105+
return logins
106+
}
107+
108+
// DisplayNames returns a list of display names for the assigned actors.
109+
func (a AssignedActors) DisplayNames() []string {
110+
// These display names are used for populating the "default" assigned actors
111+
// from the AssignedActors type. But, this is only one piece of the puzzle
112+
// as later, other queries will fetch the full list of possible assignable
113+
// actors from the repository, and the two lists will be reconciled.
114+
//
115+
// It's important that the display names are the same between the defaults
116+
// (the values returned here) and the full list (the values returned by
117+
// other repository queries). Any discrepancy would result in an
118+
// "invalid default", which means an assigned actor will not be matched
119+
// to an assignable actor and not presented as a "default" selection.
120+
// Not being presented as a default would cause the actor to be potentially
121+
// unassigned if the edits were submitted.
122+
//
123+
// To prevent this, we need shared logic to look up an actor's display name.
124+
// However, our API types between assignedActors and the full list of
125+
// assignableActors are different. So, as an attempt to maintain
126+
// consistency we convert the assignedActors to the same types as the
127+
// repository's assignableActors, treating the assignableActors DisplayName
128+
// methods as the sources of truth.
129+
// TODO KW: make this comment less of a wall of text if needed.
130+
var displayNames []string
131+
for _, a := range a.Nodes {
132+
if a.TypeName == "User" {
133+
u := NewAssignableUser(
134+
a.ID,
135+
a.Login,
136+
a.Name,
137+
)
138+
displayNames = append(displayNames, u.DisplayName())
139+
} else if a.TypeName == "Bot" {
140+
b := NewAssignableBot(
141+
a.ID,
142+
a.Login,
143+
)
144+
displayNames = append(displayNames, b.DisplayName())
145+
}
146+
}
147+
return displayNames
148+
}
149+
94150
type Labels struct {
95151
Nodes []IssueLabel
96152
TotalCount int

api/queries_pr.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type PullRequest struct {
8484
}
8585

8686
Assignees Assignees
87+
AssignedActors AssignedActors
8788
Labels Labels
8889
ProjectCards ProjectCards
8990
ProjectItems ProjectItems

0 commit comments

Comments
 (0)