@@ -38,6 +38,7 @@ type Issue struct {
38
38
Comments Comments
39
39
Author Author
40
40
Assignees Assignees
41
+ AssignedActors AssignedActors
41
42
Labels Labels
42
43
ProjectCards ProjectCards
43
44
ProjectItems ProjectItems
@@ -91,6 +92,61 @@ func (a Assignees) Logins() []string {
91
92
return logins
92
93
}
93
94
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
+
94
150
type Labels struct {
95
151
Nodes []IssueLabel
96
152
TotalCount int
0 commit comments