Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GHG-654] Added mentions on sidebar buttons / rhs bar #775

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
12 changes: 7 additions & 5 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
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 @@ -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)"`
}
31 changes: 25 additions & 6 deletions server/plugin/graphql/lhs_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
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, org, rhsState} = getSidebarData(state);
const {username, mentions, reviews, yourPrs, yourAssignments, unreads, enterpriseURL, org, 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,
org: 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 @@ -103,7 +104,7 @@ export default class SidebarRight extends React.PureComponent {
render() {
const baseURL = this.props.enterpriseURL ? this.props.enterpriseURL : 'https://github.com';
const orgQuery = this.props.org ? '+org%3A' + this.props.org : '';
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 @@ -116,6 +117,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,4 +10,5 @@ export const RHSStates = {
REVIEWS: 'reviews',
UNREADS: 'unreads',
ASSIGNMENTS: 'assignments',
MENTIONS: 'mentions',
};
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
2 changes: 2 additions & 0 deletions webapp/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ function mapPrsToDetails(prs: GithubIssueData[], details: PrsDetailsData[]) {

export const getSidebarData = createSelector(
getPluginState,

(pluginState): SidebarData => {
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,
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 @@ -93,6 +93,7 @@ export type UnreadsData = {
}

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

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