From 2608197665120cdd99d5deae9fb01fe7bee6f20e Mon Sep 17 00:00:00 2001 From: Raghav Aggarwal Date: Fri, 12 Jan 2024 14:36:16 +0530 Subject: [PATCH] [MM-17] Fix issues in release 2.2.0 (#721) * [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 * [MM-123] Review fixes: changed function names --------- Co-authored-by: Ben Schumacher --- server/plugin/graphql/lhs_query.go | 23 +++++++++++++ server/plugin/graphql/lhs_request.go | 33 +++++++++++++++---- server/plugin/plugin.go | 8 +++-- .../components/sidebar_right/github_items.tsx | 4 +-- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/server/plugin/graphql/lhs_query.go b/server/plugin/graphql/lhs_query.go index 29c17a76c..3de215e0a 100644 --- a/server/plugin/graphql/lhs_query.go +++ b/server/plugin/graphql/lhs_query.go @@ -15,6 +15,11 @@ type ( Login githubv4.String } + labelNode struct { + Name githubv4.String + Color githubv4.String + } + prSearchNodes struct { PullRequest struct { Body githubv4.String @@ -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"` } ) @@ -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 { @@ -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"` } ) diff --git a/server/plugin/graphql/lhs_request.go b/server/plugin/graphql/lhs_request.go index 8c7d2db0c..286098609 100644 --- a/server/plugin/graphql/lhs_request.go +++ b/server/plugin/graphql/lhs_request.go @@ -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) } @@ -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 @@ -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, } } diff --git a/server/plugin/plugin.go b/server/plugin/plugin.go index d3b1e3f66..a1b61203f 100644 --- a/server/plugin/plugin.go +++ b/server/plugin/plugin.go @@ -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) } @@ -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 } diff --git a/webapp/src/components/sidebar_right/github_items.tsx b/webapp/src/components/sidebar_right/github_items.tsx index 0c41e1a61..381091883 100644 --- a/webapp/src/components/sidebar_right/github_items.tsx +++ b/webapp/src/components/sidebar_right/github_items.tsx @@ -167,7 +167,7 @@ function GithubItems(props: GithubItemsProps) { } let milestone: JSX.Element | null = null; - if (item.milestone) { + if (item.milestone?.title) { milestone = ( { return (