diff --git a/server/plugin/api.go b/server/plugin/api.go index 5f69b6b52..e0cbba81d 100644 --- a/server/plugin/api.go +++ b/server/plugin/api.go @@ -66,6 +66,7 @@ type SidebarContent struct { PRs []*github.Issue `json:"prs"` Reviews []*github.Issue `json:"reviews"` Assignments []*github.Issue `json:"assignments"` + Mentions []*github.Issue `json:"mentions"` Unreads []*FilteredNotification `json:"unreads"` } @@ -938,19 +939,19 @@ func (p *Plugin) createIssueComment(c *UserContext, w http.ResponseWriter, r *ht p.writeJSON(w, result) } -func (p *Plugin) getLHSData(c *UserContext) (reviewResp []*github.Issue, assignmentResp []*github.Issue, openPRResp []*github.Issue, err error) { +func (p *Plugin) getLHSData(c *UserContext) (reviewResp []*github.Issue, assignmentResp []*github.Issue, openPRResp []*github.Issue, mentionResp []*github.Issue, err error) { graphQLClient := p.graphQLConnect(c.GHInfo) - reviewResp, assignmentResp, openPRResp, err = graphQLClient.GetLHSData(c.Context.Ctx) + reviewResp, assignmentResp, openPRResp, mentionResp, err = graphQLClient.GetLHSData(c.Context.Ctx) if err != nil { - return []*github.Issue{}, []*github.Issue{}, []*github.Issue{}, err + return []*github.Issue{}, []*github.Issue{}, []*github.Issue{}, []*github.Issue{}, err } - return reviewResp, assignmentResp, openPRResp, nil + return reviewResp, assignmentResp, openPRResp, mentionResp, nil } func (p *Plugin) getSidebarData(c *UserContext) (*SidebarContent, error) { - reviewResp, assignmentResp, openPRResp, err := p.getLHSData(c) + reviewResp, assignmentResp, openPRResp, mentionsResp, err := p.getLHSData(c) if err != nil { return nil, err } @@ -959,6 +960,7 @@ func (p *Plugin) getSidebarData(c *UserContext) (*SidebarContent, error) { PRs: openPRResp, Assignments: assignmentResp, Reviews: reviewResp, + Mentions: mentionsResp, Unreads: p.getUnreadsData(c), }, nil } diff --git a/server/plugin/graphql/lhs_query.go b/server/plugin/graphql/lhs_query.go index 3de215e0a..7b6f06f86 100644 --- a/server/plugin/graphql/lhs_query.go +++ b/server/plugin/graphql/lhs_query.go @@ -111,4 +111,13 @@ var mainQuery struct { HasNextPage bool } } `graphql:"graphql: search(first:100, after:$openPrsCursor, query: $prOpenQueryArg, type: ISSUE)"` + + Mentions struct { + IssueCount int + Nodes []prSearchNodes + PageInfo struct { + EndCursor githubv4.String + HasNextPage bool + } + } `graphql:"mentions: search(first:100, after:$mentionsCursor, query: $prMentionsQueryArg, type: ISSUE)"` } diff --git a/server/plugin/graphql/lhs_request.go b/server/plugin/graphql/lhs_request.go index 46161e1fc..708a4d05b 100644 --- a/server/plugin/graphql/lhs_request.go +++ b/server/plugin/graphql/lhs_request.go @@ -13,38 +13,57 @@ const ( queryParamReviewsCursor = "reviewsCursor" queryParamAssignmentsCursor = "assignmentsCursor" queryParamOpenPRsCursor = "openPrsCursor" + queryParamMentionsCursor = "mentionsCursor" queryParamOpenPRQueryArg = "prOpenQueryArg" queryParamReviewPRQueryArg = "prReviewQueryArg" queryParamAssigneeQueryArg = "assigneeQueryArg" + queryParamMentionsQueryArg = "prMentionsQueryArg" ) -func (c *Client) GetLHSData(ctx context.Context) ([]*github.Issue, []*github.Issue, []*github.Issue, error) { +func (c *Client) GetLHSData(ctx context.Context) ([]*github.Issue, []*github.Issue, []*github.Issue, []*github.Issue, error) { params := map[string]interface{}{ queryParamOpenPRQueryArg: githubv4.String(fmt.Sprintf("author:%s is:pr is:%s archived:false", c.username, githubv4.PullRequestStateOpen)), queryParamReviewPRQueryArg: githubv4.String(fmt.Sprintf("review-requested:%s is:pr is:%s archived:false", c.username, githubv4.PullRequestStateOpen)), queryParamAssigneeQueryArg: githubv4.String(fmt.Sprintf("assignee:%s is:%s archived:false", c.username, githubv4.PullRequestStateOpen)), + queryParamMentionsQueryArg: githubv4.String(fmt.Sprintf("mentions:%s is:%s is:pr archived:false", c.username, githubv4.PullRequestStateOpen)), queryParamReviewsCursor: (*githubv4.String)(nil), queryParamAssignmentsCursor: (*githubv4.String)(nil), queryParamOpenPRsCursor: (*githubv4.String)(nil), + queryParamMentionsCursor: (*githubv4.String)(nil), } if c.org != "" { params[queryParamOpenPRQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", c.org, params[queryParamOpenPRQueryArg])) params[queryParamReviewPRQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", c.org, params[queryParamReviewPRQueryArg])) params[queryParamAssigneeQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", c.org, params[queryParamAssigneeQueryArg])) + params[queryParamMentionsQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", c.org, params[queryParamMentionsQueryArg])) } - var resultReview, resultAssignee, resultOpenPR []*github.Issue - allReviewRequestsFetched, allAssignmentsFetched, allOpenPRsFetched := false, false, false + var resultReview, resultAssignee, resultOpenPR, resultMention []*github.Issue + allReviewRequestsFetched, allAssignmentsFetched, allOpenPRsFetched, allMentionsFetched := false, false, false, false for { - if allReviewRequestsFetched && allAssignmentsFetched && allOpenPRsFetched { + if allReviewRequestsFetched && allAssignmentsFetched && allOpenPRsFetched && allMentionsFetched { break } if err := c.executeQuery(ctx, &mainQuery, params); err != nil { - return nil, nil, nil, errors.Wrap(err, "Not able to excute the query") + return nil, nil, nil, nil, errors.Wrap(err, "Not able to excute the query") + } + + if !allMentionsFetched { + for i := range mainQuery.Mentions.Nodes { + resp := mainQuery.Mentions.Nodes[i] + pr := getPR(&resp) + resultMention = append(resultMention, pr) + } + + if !mainQuery.Mentions.PageInfo.HasNextPage { + allMentionsFetched = true + } + + params[queryParamMentionsCursor] = githubv4.NewString(mainQuery.Mentions.PageInfo.EndCursor) } if !allReviewRequestsFetched { @@ -90,7 +109,7 @@ func (c *Client) GetLHSData(ctx context.Context) ([]*github.Issue, []*github.Iss } } - return resultReview, resultAssignee, resultOpenPR, nil + return resultReview, resultAssignee, resultOpenPR, resultMention, nil } func getPR(prResp *prSearchNodes) *github.Issue { diff --git a/webapp/src/components/sidebar_buttons/index.js b/webapp/src/components/sidebar_buttons/index.js index 6ecc4aebb..88dc774d6 100644 --- a/webapp/src/components/sidebar_buttons/index.js +++ b/webapp/src/components/sidebar_buttons/index.js @@ -15,6 +15,7 @@ function mapStateToProps(state) { return { connected: state[`plugins-${pluginId}`].connected, clientId: state[`plugins-${pluginId}`].clientId, + mentions: state[`plugins-${pluginId}`].sidebarContent.mentions, reviews: state[`plugins-${pluginId}`].sidebarContent.reviews, yourPrs: state[`plugins-${pluginId}`].sidebarContent.prs, yourAssignments: state[`plugins-${pluginId}`].sidebarContent.assignments, diff --git a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx index 63d1d5c8b..1df9a3cc4 100644 --- a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx +++ b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx @@ -14,6 +14,7 @@ export default class SidebarButtons extends React.PureComponent { connected: PropTypes.bool, clientId: PropTypes.string, enterpriseURL: PropTypes.string, + mentions: PropTypes.arrayOf(PropTypes.object), reviews: PropTypes.arrayOf(PropTypes.object), unreads: PropTypes.arrayOf(PropTypes.object), yourPrs: PropTypes.arrayOf(PropTypes.object), @@ -191,6 +192,18 @@ export default class SidebarButtons extends React.PureComponent { {' ' + unreads.length} + {'Mentions on Pull Requests'}} + > + this.openRHS(RHSStates.MENTIONS)} + style={button} + > + + + { const {username, sidebarContent, reviewDetails, yourPrDetails, organization, rhsState} = pluginState; return { username, + mentions: sidebarContent.mentions || emptyArray, reviews: mapPrsToDetails(sidebarContent.reviews || emptyArray, reviewDetails), yourPrs: mapPrsToDetails(sidebarContent.prs || emptyArray, yourPrDetails), yourAssignments: sidebarContent.assignments || emptyArray, diff --git a/webapp/src/types/github_types.ts b/webapp/src/types/github_types.ts index 27aeb4941..52bcb0876 100644 --- a/webapp/src/types/github_types.ts +++ b/webapp/src/types/github_types.ts @@ -93,6 +93,7 @@ export type UnreadsData = { } export type SidebarContentData = { + mentions: GithubIssueData[]; prs: GithubIssueData[]; reviews: GithubIssueData[]; assignments: GithubIssueData[]; @@ -132,6 +133,7 @@ export type APIError = { export type SidebarData = { username: string; + mentions: GithubIssueData[]; reviews: GithubIssueData[]; yourPrs: GithubIssueData[]; yourAssignments: GithubIssueData[],