Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type SidebarContent struct {
Reviews []*graphql.GithubPRDetails `json:"reviews"`
Assignments []*github.Issue `json:"assignments"`
Unreads []*FilteredNotification `json:"unreads"`
Mentions []*graphql.GithubPRDetails `json:"mentions"`
}

type Context struct {
Expand Down Expand Up @@ -1038,19 +1039,19 @@ func (p *Plugin) createIssueComment(c *UserContext, w http.ResponseWriter, r *ht
p.writeJSON(w, result)
}

func (p *Plugin) getLHSData(c *UserContext) (reviewResp []*graphql.GithubPRDetails, assignmentResp []*github.Issue, openPRResp []*graphql.GithubPRDetails, err error) {
func (p *Plugin) getLHSData(c *UserContext) (reviewResp []*graphql.GithubPRDetails, assignmentResp []*github.Issue, openPRResp []*graphql.GithubPRDetails, mentionsResp []*graphql.GithubPRDetails, err error) {
graphQLClient := p.graphQLConnect(c.GHInfo)

reviewResp, assignmentResp, openPRResp, err = graphQLClient.GetLHSData(c.Context.Ctx)
reviewResp, assignmentResp, openPRResp, mentionsResp, err = graphQLClient.GetLHSData(c.Context.Ctx)
if err != nil {
return []*graphql.GithubPRDetails{}, []*github.Issue{}, []*graphql.GithubPRDetails{}, err
return []*graphql.GithubPRDetails{}, []*github.Issue{}, []*graphql.GithubPRDetails{}, []*graphql.GithubPRDetails{}, err
}

return reviewResp, assignmentResp, openPRResp, nil
return reviewResp, assignmentResp, openPRResp, mentionsResp, 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
}
Expand All @@ -1059,6 +1060,7 @@ func (p *Plugin) getSidebarData(c *UserContext) (*SidebarContent, error) {
PRs: openPRResp,
Assignments: assignmentResp,
Reviews: reviewResp,
Mentions: mentionsResp,
Unreads: p.getUnreadsData(c),
}, nil
}
Expand Down
9 changes: 9 additions & 0 deletions server/plugin/graphql/lhs_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,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)"`
}
47 changes: 34 additions & 13 deletions server/plugin/graphql/lhs_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ const (
queryParamReviewsCursor = "reviewsCursor"
queryParamAssignmentsCursor = "assignmentsCursor"
queryParamOpenPRsCursor = "openPrsCursor"
queryParamMentionsCursor = "mentionsCursor"

queryParamOpenPRQueryArg = "prOpenQueryArg"
queryParamReviewPRQueryArg = "prReviewQueryArg"
queryParamAssigneeQueryArg = "assigneeQueryArg"
queryParamMentionsQueryArg = "prMentionsQueryArg"
)

type GithubPRDetails struct {
Expand All @@ -29,62 +31,67 @@ type GithubPRDetails struct {
ChangedFiles *githubv4.Int `json:"changed_files,omitempty"`
}

func (c *Client) GetLHSData(ctx context.Context) ([]*GithubPRDetails, []*github.Issue, []*GithubPRDetails, error) {
func (c *Client) GetLHSData(ctx context.Context) ([]*GithubPRDetails, []*github.Issue, []*GithubPRDetails, []*GithubPRDetails, error) {
orgsList := c.getOrganizations()
var resultAssignee []*github.Issue
var resultReview, resultOpenPR []*GithubPRDetails
var resultReview, resultOpenPR, resultMentions []*GithubPRDetails

var err error
for _, org := range orgsList {
resultReview, resultAssignee, resultOpenPR, err = c.fetchLHSData(ctx, resultReview, resultAssignee, resultOpenPR, org, c.username)
resultReview, resultAssignee, resultOpenPR, resultMentions, err = c.fetchLHSData(ctx, resultReview, resultAssignee, resultOpenPR, resultMentions, org, c.username)
if err != nil {
c.logger.Error("Error fetching LHS data for org", "org", org, "error", err.Error())
}
}

if len(orgsList) == 0 {
return c.fetchLHSData(ctx, resultReview, resultAssignee, resultOpenPR, "", c.username)
return c.fetchLHSData(ctx, resultReview, resultAssignee, resultOpenPR, resultMentions, "", c.username)
}

return resultReview, resultAssignee, resultOpenPR, nil
return resultReview, resultAssignee, resultOpenPR, resultMentions, nil
}

func (c *Client) fetchLHSData(
ctx context.Context,
resultReview []*GithubPRDetails,
resultAssignee []*github.Issue,
resultOpenPR []*GithubPRDetails,
resultMentions []*GithubPRDetails,
org string,
username string,
) ([]*GithubPRDetails, []*github.Issue, []*GithubPRDetails, error) {
) ([]*GithubPRDetails, []*github.Issue, []*GithubPRDetails, []*GithubPRDetails, error) {
baseOpenPR := fmt.Sprintf("author:%s is:pr is:%s archived:false", username, githubv4.PullRequestStateOpen)
baseReviewPR := fmt.Sprintf("review-requested:%s is:pr is:%s archived:false", username, githubv4.PullRequestStateOpen)
baseAssignee := fmt.Sprintf("assignee:%s is:%s archived:false", username, githubv4.PullRequestStateOpen)
baseMentions := fmt.Sprintf("mentions:%s is:%s is:pr archived:false", c.username, githubv4.PullRequestStateOpen)

if org != "" {
baseOpenPR = fmt.Sprintf("org:%s %s", org, baseOpenPR)
baseReviewPR = fmt.Sprintf("org:%s %s", org, baseReviewPR)
baseAssignee = fmt.Sprintf("org:%s %s", org, baseAssignee)
baseMentions = fmt.Sprintf("org:%s %s", org, baseMentions)
}

params := map[string]interface{}{
queryParamOpenPRQueryArg: githubv4.String(baseOpenPR),
queryParamReviewPRQueryArg: githubv4.String(baseReviewPR),
queryParamAssigneeQueryArg: githubv4.String(baseAssignee),
queryParamOpenPRQueryArg: githubv4.String(baseOpenPR),
queryParamReviewPRQueryArg: githubv4.String(baseReviewPR),
queryParamAssigneeQueryArg: githubv4.String(baseAssignee),
queryParamMentionsQueryArg: githubv4.String(baseMentions),

queryParamReviewsCursor: (*githubv4.String)(nil),
queryParamAssignmentsCursor: (*githubv4.String)(nil),
queryParamOpenPRsCursor: (*githubv4.String)(nil),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no queryParamMentionsCursor initialized here.


allReviewRequestsFetched, allAssignmentsFetched, allOpenPRsFetched := false, false, false
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 execute the query")
return nil, nil, nil, nil, errors.Wrap(err, "Not able to execute the query")
}

if !allReviewRequestsFetched {
Expand Down Expand Up @@ -128,9 +135,23 @@ func (c *Client) fetchLHSData(

params[queryParamOpenPRsCursor] = githubv4.NewString(mainQuery.OpenPullRequests.PageInfo.EndCursor)
}

if !allMentionsFetched {
for i := range mainQuery.Mentions.Nodes {
resp := mainQuery.Mentions.Nodes[i]
pr := getPR(&resp)
resultMentions = append(resultMentions, pr)
}

if !mainQuery.Mentions.PageInfo.HasNextPage {
allMentionsFetched = true
}

params[queryParamMentionsCursor] = githubv4.NewString(mainQuery.Mentions.PageInfo.EndCursor)
}
}

return resultReview, resultAssignee, resultOpenPR, nil
return resultReview, resultAssignee, resultOpenPR, resultMentions, nil
}

func getPR(prResp *prSearchNodes) *GithubPRDetails {
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/sidebar_buttons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions webapp/src/components/sidebar_buttons/sidebar_buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -191,6 +192,18 @@ export default class SidebarButtons extends React.PureComponent {
{' ' + unreads.length}
</a>
</OverlayTrigger>
<OverlayTrigger
key='githubMentionsLink'
placement={placement}
overlay={<Tooltip id='mentionTooltip'>{'Mentions on Pull Requests'}</Tooltip>}
>
<a
onClick={() => this.openRHS(RHSStates.MENTIONS)}
style={button}
>
<i className='fa fa-comment-o'/>
</a>
</OverlayTrigger>
<OverlayTrigger
key='githubRefreshButton'
placement={placement}
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/sidebar_right/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {getSidebarData} from 'src/selectors';
import SidebarRight from './sidebar_right.jsx';

function mapStateToProps(state) {
const {username, reviews, yourPrs, yourAssignments, unreads, enterpriseURL, orgs, rhsState} = getSidebarData(state);
const {username, mentions, reviews, yourPrs, yourAssignments, unreads, enterpriseURL, orgs, rhsState} = getSidebarData(state);
return {
username,
reviews,
yourPrs,
mentions,
yourAssignments,
unreads,
enterpriseURL,
Expand Down
10 changes: 9 additions & 1 deletion webapp/src/components/sidebar_right/sidebar_right.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class SidebarRight extends React.PureComponent {
username: PropTypes.string,
orgs: PropTypes.array.isRequired,
enterpriseURL: PropTypes.string,
mentions: PropTypes.arrayOf(PropTypes.object),
reviews: PropTypes.arrayOf(PropTypes.object),
unreads: PropTypes.arrayOf(PropTypes.object),
yourPrs: PropTypes.arrayOf(PropTypes.object),
Expand Down Expand Up @@ -107,7 +108,7 @@ export default class SidebarRight extends React.PureComponent {
orgQuery += ('+org%3A' + org);
return orgQuery;
});
const {yourPrs, reviews, unreads, yourAssignments, username, rhsState} = this.props;
const {yourPrs, mentions, reviews, unreads, yourAssignments, username, rhsState} = this.props;

let title = '';
let githubItems = [];
Expand All @@ -120,6 +121,13 @@ export default class SidebarRight extends React.PureComponent {
title = 'Your Open Pull Requests';
listUrl = baseURL + '/pulls?q=is%3Aopen+is%3Apr+author%3A' + username + '+archived%3Afalse' + orgQuery;

break;
case RHSStates.MENTIONS:

githubItems = mentions;
title = 'Your mentions';
listUrl = baseURL + '/pulls?q=is%3Aopen+is%3Apr+mentions%3A' + username + '+archived%3Afalse' + orgQuery;

break;
case RHSStates.REVIEWS:

Expand Down
1 change: 1 addition & 0 deletions webapp/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const RHSStates = {
REVIEWS: 'reviews',
UNREADS: 'unreads',
ASSIGNMENTS: 'assignments',
MENTIONS: 'mentions',
};

export const ReviewState = {
Expand Down
1 change: 1 addition & 0 deletions webapp/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function sidebarContent(state = {
assignments: [],
prs: [],
unreads: [],
mentions: [],
} as SidebarContentData, action: {type: string, data: SidebarContentData}) {
switch (action.type) {
case ActionTypes.RECEIVED_SIDEBAR_CONTENT:
Expand Down
1 change: 1 addition & 0 deletions webapp/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const getSidebarData = createSelector(
const {username, sidebarContent, reviewDetails, yourPrDetails, organizations, rhsState} = pluginState;
return {
username,
mentions: sidebarContent.mentions || emptyArray,
reviews: mapPrsToDetails(sidebarContent.reviews || emptyArray, reviewDetails),
yourPrs: mapPrsToDetails(sidebarContent.prs || emptyArray, yourPrDetails),
yourAssignments: sidebarContent.assignments || emptyArray,
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/types/github_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export type UnreadsData = {
}

export type SidebarContentData = {
mentions: GithubIssueData[];
prs: GithubIssueData[];
reviews: GithubIssueData[];
assignments: GithubIssueData[];
Expand Down Expand Up @@ -162,6 +163,7 @@ export type APIError = {

export type SidebarData = {
username: string;
mentions: GithubIssueData[];
reviews: GithubIssueData[];
yourPrs: GithubIssueData[];
yourAssignments: GithubIssueData[],
Expand Down
Loading