Skip to content

Commit

Permalink
[MM-17] Fix issues in release 2.2.0 (#721)
Browse files Browse the repository at this point in the history
* [MM-17] Fix issues in release 2.2.0:
1. Mention notifications not working.
2. Labels and milestones not getting displayed in the RHS.

* Empty-Commit

* [MM-17] Review fixes

* Review fix

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>

* [MM-123] Review fixes: changed function names

---------

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
  • Loading branch information
raghavaggarwal2308 and hanzei committed Jan 12, 2024
1 parent 5aa2450 commit 2608197
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
23 changes: 23 additions & 0 deletions server/plugin/graphql/lhs_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type (
Login githubv4.String
}

labelNode struct {
Name githubv4.String
Color githubv4.String
}

prSearchNodes struct {
PullRequest struct {
Body githubv4.String
Expand All @@ -27,6 +32,12 @@ type (
Title githubv4.String
Author authorQuery
URL githubv4.URI
Labels struct {
Nodes []labelNode
} `graphql:"labels(first:100)"`
Milestone struct {
Title githubv4.String
}
} `graphql:"... on PullRequest"`
}
)
Expand All @@ -44,6 +55,12 @@ type (
Title githubv4.String
Author authorQuery
URL githubv4.URI
Labels struct {
Nodes []labelNode
} `graphql:"labels(first:100)"`
Milestone struct {
Title githubv4.String
}
} `graphql:"... on Issue"`

PullRequest struct {
Expand All @@ -57,6 +74,12 @@ type (
Title githubv4.String
Author authorQuery
URL githubv4.URI
Labels struct {
Nodes []labelNode
} `graphql:"labels(first:100)"`
Milestone struct {
Title githubv4.String
}
} `graphql:"... on PullRequest"`
}
)
Expand Down
33 changes: 27 additions & 6 deletions server/plugin/graphql/lhs_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *Client) GetLHSData(ctx context.Context) ([]*github.Issue, []*github.Iss
if !allAssignmentsFetched {
for i := range mainQuery.Assignments.Nodes {
resp := mainQuery.Assignments.Nodes[i]
issue := getIssue(&resp)
issue := newIssueFromAssignmentResponse(&resp)
resultAssignee = append(resultAssignee, issue)
}

Expand Down Expand Up @@ -95,21 +95,38 @@ func (c *Client) GetLHSData(ctx context.Context) ([]*github.Issue, []*github.Iss

func getPR(prResp *prSearchNodes) *github.Issue {
resp := prResp.PullRequest
labels := getGithubLabels(resp.Labels.Nodes)

return getGithubIssue(resp.Number, resp.Title, resp.Author.Login, resp.Repository.URL, resp.URL, resp.CreatedAt, resp.UpdatedAt)
return newGithubIssue(resp.Number, resp.Title, resp.Author.Login, resp.Repository.URL, resp.URL, resp.CreatedAt, resp.UpdatedAt, labels, resp.Milestone.Title)
}

func getIssue(assignmentResp *assignmentSearchNodes) *github.Issue {
func newIssueFromAssignmentResponse(assignmentResp *assignmentSearchNodes) *github.Issue {
resp := assignmentResp.PullRequest
labels := getGithubLabels(resp.Labels.Nodes)

return getGithubIssue(resp.Number, resp.Title, resp.Author.Login, resp.Repository.URL, resp.URL, resp.CreatedAt, resp.UpdatedAt)
return newGithubIssue(resp.Number, resp.Title, resp.Author.Login, resp.Repository.URL, resp.URL, resp.CreatedAt, resp.UpdatedAt, labels, resp.Milestone.Title)
}

func getGithubIssue(prNumber githubv4.Int, title, login githubv4.String, repositoryURL, htmlURL githubv4.URI, createdAt, updatedAt githubv4.DateTime) *github.Issue {
func getGithubLabels(labels []labelNode) []*github.Label {
githubLabels := []*github.Label{}
for _, label := range labels {
name := (string)(label.Name)
color := (string)(label.Color)
githubLabels = append(githubLabels, &github.Label{
Color: &color,
Name: &name,
})
}

return githubLabels
}

func newGithubIssue(prNumber githubv4.Int, title, login githubv4.String, repositoryURL, htmlURL githubv4.URI, createdAt, updatedAt githubv4.DateTime, labels []*github.Label, milestone githubv4.String) *github.Issue {
number := int(prNumber)
repoURL := repositoryURL.String()
issuetitle := string(title)
userLogin := (string)(login)
userLogin := string(login)
milestoneTitle := string(milestone)
url := htmlURL.String()
createdAtTime := createdAt.Time
updatedAtTime := updatedAt.Time
Expand All @@ -123,6 +140,10 @@ func getGithubIssue(prNumber githubv4.Int, title, login githubv4.String, reposit
User: &github.User{
Login: &userLogin,
},
Milestone: &github.Milestone{
Title: &milestoneTitle,
},
HTMLURL: &url,
Labels: labels,
}
}
8 changes: 6 additions & 2 deletions server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,11 @@ func (p *Plugin) storeGitHubToUserIDMapping(githubUsername, userID string) error

func (p *Plugin) getGitHubToUserIDMapping(githubUsername string) string {
var data []byte
_ = p.client.KV.Get(githubUsername+githubUsernameKey, data)
err := p.client.KV.Get(githubUsername+githubUsernameKey, &data)
if err != nil {
p.API.LogWarn("Error occurred while getting the user ID from KV store using the Github username", "Error", err.Error())
return ""
}

return string(data)
}
Expand Down Expand Up @@ -748,7 +752,7 @@ func (p *Plugin) StoreDailySummaryText(userID, summaryText string) error {

func (p *Plugin) GetDailySummaryText(userID string) (string, error) {
var summaryByte []byte
err := p.client.KV.Get(userID+dailySummary, summaryByte)
err := p.client.KV.Get(userID+dailySummary, &summaryByte)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/sidebar_right/github_items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function GithubItems(props: GithubItemsProps) {
}

let milestone: JSX.Element | null = null;
if (item.milestone) {
if (item.milestone?.title) {
milestone = (
<span
title={item.milestone.title}
Expand Down Expand Up @@ -372,7 +372,7 @@ function getGithubLabels(labels: Label[]) {
return labels.map((label) => {
return (
<Badge
key={label.id}
key={label.name}
aria-label={label.name}
role={'note'}
style={{...itemStyle, ...{backgroundColor: `#${label.color}`, color: getLabelFontColor(label.color)}}}
Expand Down

0 comments on commit 2608197

Please sign in to comment.