11package status
22
33import (
4+ "fmt"
5+ "net/http"
6+ "net/url"
7+
48 "github.com/cli/cli/v2/api"
9+ "github.com/cli/cli/v2/internal/ghinstance"
510 "github.com/cli/cli/v2/internal/ghrepo"
611 "github.com/cli/cli/v2/pkg/cmdutil"
712 "github.com/spf13/cobra"
813)
914
1015type StatusOptions struct {
1116 BaseRepo func () (ghrepo.Interface , error )
17+ HttpClient func () (* http.Client , error )
1218 HasRepoOverride bool
1319 Org string
1420}
1521
1622func NewCmdStatus (f * cmdutil.Factory , runF func (* StatusOptions ) error ) * cobra.Command {
1723 opts := & StatusOptions {}
24+ opts .HttpClient = f .HttpClient
1825 cmd := & cobra.Command {
1926 Use : "status" ,
2027 Short : "Print information about relevant issues, pull requests, and notifications across repositories" ,
@@ -36,19 +43,102 @@ func NewCmdStatus(f *cmdutil.Factory, runF func(*StatusOptions) error) *cobra.Co
3643 return cmd
3744}
3845
39- type gqlResults struct {
40- ReviewRequests []api.PullRequest
41- AssignedPRs []api.PullRequest
42- AssignedIssues []api.PullRequest
46+ /*
47+ • "repo activity"
48+ • using notification API
49+ • new issues
50+ • new prs
51+ • comments
52+ • mentions
53+ • using notifications API
54+ • review requests
55+ • using search API
56+ • pr assignments
57+ • using search API
58+ • issue assignments
59+ • using search API
60+ */
61+
62+ type Notification struct {
63+ Reason string
64+ Subject struct {
65+ Title string
66+ LatestCommentURL string `json:"latest_comment_url"`
67+ URL string
68+ Type string
69+ }
70+ Repository struct {
71+ FullName string `json:"full_name"`
72+ }
73+ }
74+
75+ func getNotifications (client * http.Client ) ([]Notification , error ) {
76+ apiClient := api .NewClientFromHTTP (client )
77+ query := url.Values {}
78+ query .Add ("per_page" , "100" )
79+ // TODO might want to get multiple pages since I'm sorting the results into buckets
80+ p := fmt .Sprintf ("notifications?%s" , query .Encode ())
81+ var resp []Notification
82+ err := apiClient .REST (ghinstance .Default (), "GET" , p , nil , & resp )
83+ if err != nil {
84+ return nil , fmt .Errorf ("could not get notifications: %w" , err )
85+ }
86+
87+ return resp , nil
4388}
4489
4590func statusRun (opts * StatusOptions ) error {
91+ client , err := opts .HttpClient ()
92+ if err != nil {
93+ return fmt .Errorf ("could not create client: %w" , err )
94+ }
95+ ns , err := getNotifications (client )
96+ if err != nil {
97+ return err
98+ }
99+
100+ mentions := []Notification {}
101+ newIssues := []Notification {}
102+ newPRs := []Notification {}
103+ comments := []Notification {}
104+
105+ for _ , n := range ns {
106+ if n .Reason == "mention" {
107+ mentions = append (mentions , n )
108+ continue
109+ }
110+ if n .Subject .LatestCommentURL == n .Subject .URL {
111+ if n .Subject .Type == "PullRequest" {
112+ newPRs = append (newPRs , n )
113+ } else if n .Subject .Type == "Issue" {
114+ newIssues = append (newIssues , n )
115+ } else {
116+ // TODO i donno
117+ fmt .Printf ("DBG %#v\n " , n )
118+ }
119+ } else {
120+ comments = append (comments , n )
121+ }
122+ }
123+
124+ // this is picking up stuff like team mentions. i should handle those explicitly.
125+
126+ fmt .Println ("MENTIONS" )
127+ fmt .Printf ("%#v\n " , mentions )
128+ fmt .Println ("NEW PRs" )
129+ fmt .Printf ("%#v\n " , newPRs )
130+ fmt .Println ("NEW ISSUES" )
131+ fmt .Printf ("%#v\n " , newIssues )
132+ fmt .Println ("COMMENTS" )
133+ fmt .Printf ("%#v\n " , comments )
134+
46135 // should i attempt to shoehorn all of this into a single giant graphql
47136 // query? i guess everything that is in graphql should be trated that way.
48137
49138 // TODO review requests -- GQL search
50139 // TODO pr assignments -- GQL search
51140 // TODO issue assignments -- GQL search
141+ // TODO discussions -- GQL search
52142 // TODO mentions -- GQL, apparently. can this include discussions? continue to study mislav's extension
53143
54144 // TODO figure out if this could work:
0 commit comments