@@ -2,52 +2,45 @@ package api
22
33import (
44 "fmt"
5- "time"
65)
76
87type IssuesPayload struct {
98 Assigned []Issue
109 Mentioned []Issue
11- Recent []Issue
10+ Authored []Issue
1211}
1312
1413type Issue struct {
15- Number int
16- Title string
17- URL string
18- Labels []string
19- TotalLabelCount int
14+ Number int
15+ Title string
16+ URL string
17+ State string
18+
19+ Labels struct {
20+ Nodes []IssueLabel
21+ TotalCount int
22+ }
23+ }
24+
25+ type IssueLabel struct {
26+ Name string
2027}
2128
2229type apiIssues struct {
2330 Issues struct {
24- Edges []struct {
25- Node struct {
26- Number int
27- Title string
28- URL string
29- Labels struct {
30- Edges []struct {
31- Node struct {
32- Name string
33- }
34- }
35- TotalCount int
36- }
37- }
38- }
31+ Nodes []Issue
3932 }
4033}
4134
4235const fragments = `
4336 fragment issue on Issue {
4437 number
4538 title
39+ url
40+ state
4641 labels(first: 3) {
47- edges {
48- node {
49- name
50- }
42+ nodes {
43+ name
5144 }
5245 totalCount
5346 }
@@ -97,35 +90,29 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
9790 type response struct {
9891 Assigned apiIssues
9992 Mentioned apiIssues
100- Recent apiIssues
93+ Authored apiIssues
10194 }
10295
10396 query := fragments + `
104- query($owner: String!, $repo: String!, $since: DateTime!, $ viewer: String!, $per_page: Int = 10) {
97+ query($owner: String!, $repo: String!, $viewer: String!, $per_page: Int = 10) {
10598 assigned: repository(owner: $owner, name: $repo) {
10699 issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
107- edges {
108- node {
109- ...issue
110- }
100+ nodes {
101+ ...issue
111102 }
112103 }
113104 }
114105 mentioned: repository(owner: $owner, name: $repo) {
115106 issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
116- edges {
117- node {
118- ...issue
119- }
107+ nodes {
108+ ...issue
120109 }
121110 }
122111 }
123- recent: repository(owner: $owner, name: $repo) {
124- issues(filterBy: {since: $since, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
125- edges {
126- node {
127- ...issue
128- }
112+ authored: repository(owner: $owner, name: $repo) {
113+ issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
114+ nodes {
115+ ...issue
129116 }
130117 }
131118 }
@@ -134,12 +121,10 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
134121
135122 owner := ghRepo .RepoOwner ()
136123 repo := ghRepo .RepoName ()
137- since := time .Now ().UTC ().Add (time .Hour * - 24 ).Format ("2006-01-02T15:04:05-0700" )
138124 variables := map [string ]interface {}{
139125 "owner" : owner ,
140126 "repo" : repo ,
141127 "viewer" : currentUsername ,
142- "since" : since ,
143128 }
144129
145130 var resp response
@@ -148,14 +133,10 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
148133 return nil , err
149134 }
150135
151- assigned := convertAPIToIssues (resp .Assigned )
152- mentioned := convertAPIToIssues (resp .Mentioned )
153- recent := convertAPIToIssues (resp .Recent )
154-
155136 payload := IssuesPayload {
156- assigned ,
157- mentioned ,
158- recent ,
137+ Assigned : resp . Assigned . Issues . Nodes ,
138+ Mentioned : resp . Mentioned . Issues . Nodes ,
139+ Authored : resp . Authored . Issues . Nodes ,
159140 }
160141
161142 return & payload , nil
@@ -191,10 +172,8 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig
191172 query($owner: String!, $repo: String!, $limit: Int, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
192173 repository(owner: $owner, name: $repo) {
193174 issues(first: $limit, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee}) {
194- edges {
195- node {
196- ...issue
197- }
175+ nodes {
176+ ...issue
198177 }
199178 }
200179 }
@@ -221,27 +200,5 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig
221200 return nil , err
222201 }
223202
224- issues := convertAPIToIssues (resp .Repository )
225- return issues , nil
226- }
227-
228- func convertAPIToIssues (i apiIssues ) []Issue {
229- var issues []Issue
230- for _ , edge := range i .Issues .Edges {
231- var labels []string
232- for _ , labelEdge := range edge .Node .Labels .Edges {
233- labels = append (labels , labelEdge .Node .Name )
234- }
235-
236- issue := Issue {
237- Number : edge .Node .Number ,
238- Title : edge .Node .Title ,
239- URL : edge .Node .URL ,
240- Labels : labels ,
241- TotalLabelCount : edge .Node .Labels .TotalCount ,
242- }
243- issues = append (issues , issue )
244- }
245-
246- return issues
203+ return resp .Repository .Issues .Nodes , nil
247204}
0 commit comments