@@ -16,10 +16,12 @@ const (
1616 queryParamReviewsCursor = "reviewsCursor"
1717 queryParamAssignmentsCursor = "assignmentsCursor"
1818 queryParamOpenPRsCursor = "openPrsCursor"
19+ queryParamMentionsCursor = "mentionsCursor"
1920
2021 queryParamOpenPRQueryArg = "prOpenQueryArg"
2122 queryParamReviewPRQueryArg = "prReviewQueryArg"
2223 queryParamAssigneeQueryArg = "assigneeQueryArg"
24+ queryParamMentionsQueryArg = "prMentionsQueryArg"
2325)
2426
2527type GithubPRDetails struct {
@@ -29,51 +31,54 @@ type GithubPRDetails struct {
2931 ChangedFiles * githubv4.Int `json:"changed_files,omitempty"`
3032}
3133
32- func (c * Client ) GetLHSData (ctx context.Context ) ([]* GithubPRDetails , []* github.Issue , []* GithubPRDetails , error ) {
34+ func (c * Client ) GetLHSData (ctx context.Context ) ([]* GithubPRDetails , []* github.Issue , []* GithubPRDetails , [] * github. Issue , error ) {
3335 orgsList := c .getOrganizations ()
34- var resultAssignee []* github.Issue
36+ var resultAssignee , resultMentions []* github.Issue
3537 var resultReview , resultOpenPR []* GithubPRDetails
3638
3739 params := map [string ]interface {}{
3840 queryParamOpenPRQueryArg : githubv4 .String (fmt .Sprintf ("author:%s is:pr is:%s archived:false" , c .username , githubv4 .PullRequestStateOpen )),
3941 queryParamReviewPRQueryArg : githubv4 .String (fmt .Sprintf ("review-requested:%s is:pr is:%s archived:false" , c .username , githubv4 .PullRequestStateOpen )),
4042 queryParamAssigneeQueryArg : githubv4 .String (fmt .Sprintf ("assignee:%s is:%s archived:false" , c .username , githubv4 .PullRequestStateOpen )),
43+ queryParamMentionsQueryArg : githubv4 .String (fmt .Sprintf ("mentions:%s is:%s is:pr archived:false" , c .username , githubv4 .PullRequestStateOpen )),
4144 queryParamReviewsCursor : (* githubv4 .String )(nil ),
4245 queryParamAssignmentsCursor : (* githubv4 .String )(nil ),
4346 queryParamOpenPRsCursor : (* githubv4 .String )(nil ),
47+ queryParamMentionsCursor : (* githubv4 .String )(nil ),
4448 }
4549
4650 var err error
4751 for _ , org := range orgsList {
48- resultReview , resultAssignee , resultOpenPR , err = c .fetchLHSData (ctx , resultReview , resultAssignee , resultOpenPR , org , params )
52+ resultReview , resultAssignee , resultOpenPR , resultMentions , err = c .fetchLHSData (ctx , resultReview , resultAssignee , resultOpenPR , resultMentions , org , params )
4953 if err != nil {
50- return nil , nil , nil , err
54+ return nil , nil , nil , nil , err
5155 }
5256 }
5357
5458 if len (orgsList ) == 0 {
55- return c .fetchLHSData (ctx , resultReview , resultAssignee , resultOpenPR , "" , params )
59+ return c .fetchLHSData (ctx , resultReview , resultAssignee , resultOpenPR , resultMentions , "" , params )
5660 }
5761
58- return resultReview , resultAssignee , resultOpenPR , nil
62+ return resultReview , resultAssignee , resultOpenPR , resultMentions , nil
5963}
6064
61- func (c * Client ) fetchLHSData (ctx context.Context , resultReview []* GithubPRDetails , resultAssignee []* github.Issue , resultOpenPR []* GithubPRDetails , org string , params map [string ]interface {}) ([]* GithubPRDetails , []* github.Issue , []* GithubPRDetails , error ) {
65+ func (c * Client ) fetchLHSData (ctx context.Context , resultReview []* GithubPRDetails , resultAssignee []* github.Issue , resultOpenPR []* GithubPRDetails , resultMentions [] * github. Issue , org string , params map [string ]interface {}) ([]* GithubPRDetails , []* github.Issue , []* GithubPRDetails , [] * github. Issue , error ) {
6266 if org != "" {
6367 params [queryParamOpenPRQueryArg ] = githubv4 .String (fmt .Sprintf ("org:%s %s" , org , params [queryParamOpenPRQueryArg ]))
6468 params [queryParamReviewPRQueryArg ] = githubv4 .String (fmt .Sprintf ("org:%s %s" , org , params [queryParamReviewPRQueryArg ]))
6569 params [queryParamAssigneeQueryArg ] = githubv4 .String (fmt .Sprintf ("org:%s %s" , org , params [queryParamAssigneeQueryArg ]))
70+ params [queryParamMentionsQueryArg ] = githubv4 .String (fmt .Sprintf ("org:%s %s" , c .org , params [queryParamMentionsQueryArg ]))
6671 }
6772
68- allReviewRequestsFetched , allAssignmentsFetched , allOpenPRsFetched := false , false , false
73+ allReviewRequestsFetched , allAssignmentsFetched , allOpenPRsFetched , allMentionsFetched := false , false , false , false
6974
7075 for {
71- if allReviewRequestsFetched && allAssignmentsFetched && allOpenPRsFetched {
76+ if allReviewRequestsFetched && allAssignmentsFetched && allOpenPRsFetched && allMentionsFetched {
7277 break
7378 }
7479
7580 if err := c .executeQuery (ctx , & mainQuery , params ); err != nil {
76- return nil , nil , nil , errors .Wrap (err , "Not able to excute the query" )
81+ return nil , nil , nil , nil , errors .Wrap (err , "Not able to excute the query" )
7782 }
7883
7984 if ! allReviewRequestsFetched {
@@ -117,9 +122,23 @@ func (c *Client) fetchLHSData(ctx context.Context, resultReview []*GithubPRDetai
117122
118123 params [queryParamOpenPRsCursor ] = githubv4 .NewString (mainQuery .OpenPullRequests .PageInfo .EndCursor )
119124 }
125+
126+ if ! allMentionsFetched {
127+ for i := range mainQuery .Mentions .Nodes {
128+ resp := mainQuery .Mentions .Nodes [i ]
129+ issue := newIssueFromMentionsResponse (& resp )
130+ resultMentions = append (resultMentions , issue )
131+ }
132+
133+ if ! mainQuery .Mentions .PageInfo .HasNextPage {
134+ allMentionsFetched = true
135+ }
136+
137+ params [queryParamMentionsCursor ] = githubv4 .NewString (mainQuery .Mentions .PageInfo .EndCursor )
138+ }
120139 }
121140
122- return resultReview , resultAssignee , resultOpenPR , nil
141+ return resultReview , resultAssignee , resultOpenPR , resultMentions , nil
123142}
124143
125144func getPR (prResp * prSearchNodes ) * GithubPRDetails {
@@ -164,6 +183,13 @@ func newIssueFromAssignmentResponse(assignmentResp *assignmentSearchNodes) *gith
164183 return newGithubIssue (resp .Number , resp .Title , resp .Author .Login , resp .Repository .URL , resp .URL , resp .CreatedAt , resp .UpdatedAt , labels , resp .Milestone .Title )
165184}
166185
186+ func newIssueFromMentionsResponse (assignmentResp * mentionsSearchNodes ) * github.Issue {
187+ resp := assignmentResp .PullRequest
188+ labels := getGithubLabels (resp .Labels .Nodes )
189+
190+ return newGithubIssue (resp .Number , resp .Title , resp .Author .Login , resp .Repository .URL , resp .URL , resp .CreatedAt , resp .UpdatedAt , labels , resp .Milestone .Title )
191+ }
192+
167193func getGithubLabels (labels []labelNode ) []* github.Label {
168194 githubLabels := []* github.Label {}
169195 for _ , label := range labels {
0 commit comments