@@ -2,6 +2,7 @@ package api
22
33import (
44 "fmt"
5+ "time"
56)
67
78type PullRequestsPayload struct {
@@ -22,6 +23,108 @@ type Repo interface {
2223 RepoOwner () string
2324}
2425
26+ type IssuesPayload struct {
27+ Assigned []Issue
28+ Mentioned []Issue
29+ Recent []Issue
30+ }
31+
32+ type Issue struct {
33+ Number int
34+ Title string
35+ }
36+
37+ func Issues (client * Client , ghRepo Repo , currentUsername string ) (* IssuesPayload , error ) {
38+ type issues struct {
39+ Issues struct {
40+ Edges []struct {
41+ Node Issue
42+ }
43+ }
44+ }
45+
46+ type response struct {
47+ Assigned issues
48+ Mentioned issues
49+ Recent issues
50+ }
51+
52+ query := `
53+ fragment issue on Issue {
54+ number
55+ title
56+ }
57+ query($owner: String!, $repo: String!, $since: DateTime!, $viewer: String!, $per_page: Int = 10) {
58+ assigned: repository(owner: $owner, name: $repo) {
59+ issues(filterBy: {assignee: $viewer}, first: $per_page) {
60+ edges {
61+ node {
62+ ...issue
63+ }
64+ }
65+ }
66+ }
67+ mentioned: repository(owner: $owner, name: $repo) {
68+ issues(filterBy: {mentioned: $viewer}, first: $per_page) {
69+ edges {
70+ node {
71+ ...issue
72+ }
73+ }
74+ }
75+ }
76+ recent: repository(owner: $owner, name: $repo) {
77+ issues(filterBy: {since: $since, orderBy: {field: CREATED_AT, direction: DESC}}, first: $per_page) {
78+ edges {
79+ node {
80+ ...issue
81+ }
82+ }
83+ }
84+ }
85+ }
86+ `
87+
88+ owner := ghRepo .RepoOwner ()
89+ repo := ghRepo .RepoName ()
90+ since := time .Now ().UTC ().Add (time .Hour * - 24 ).Format ("2006-01-02T15:04:05-0700" )
91+ variables := map [string ]interface {}{
92+ "owner" : owner ,
93+ "repo" : repo ,
94+ "viewer" : currentUsername ,
95+ "since" : since ,
96+ }
97+
98+ var resp response
99+ err := client .GraphQL (query , variables , & resp )
100+ if err != nil {
101+ return nil , err
102+ }
103+
104+ var assigned []Issue
105+ for _ , edge := range resp .Assigned .Issues .Edges {
106+ assigned = append (assigned , edge .Node )
107+ }
108+
109+ var mentioned []Issue
110+ for _ , edge := range resp .Mentioned .Issues .Edges {
111+ mentioned = append (mentioned , edge .Node )
112+ }
113+
114+ var recent []Issue
115+ for _ , edge := range resp .Recent .Issues .Edges {
116+ recent = append (recent , edge .Node )
117+ }
118+
119+ payload := IssuesPayload {
120+ assigned ,
121+ mentioned ,
122+ recent ,
123+ }
124+
125+ return & payload , nil
126+ }
127+
25128func PullRequests (client * Client , ghRepo Repo , currentBranch , currentUsername string ) (* PullRequestsPayload , error ) {
26129 type edges struct {
27130 Edges []struct {
0 commit comments