Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
Browse files Browse the repository at this point in the history
…ub into release-bump-2.2.0
  • Loading branch information
raghavaggarwal2308 committed Jan 15, 2024
2 parents fb518c0 + 2608197 commit 36e72f4
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 28 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ require (
github.com/wiggin77/srslog v1.0.1 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.3 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -345,17 +345,17 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
18 changes: 9 additions & 9 deletions server/plugin/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func TestSetDefaults(t *testing.T) {
for _, testCase := range []struct {
description string
isCloud bool
config Configuration
config *Configuration

shouldChange bool
outputCheck func(*testing.T, *Configuration)
errMsg string
}{
{
description: "noop",
config: Configuration{
config: &Configuration{
EncryptionKey: "abcd",
WebhookSecret: "efgh",
},
Expand All @@ -82,7 +82,7 @@ func TestSetDefaults(t *testing.T) {
},
}, {
description: "set encryption key",
config: Configuration{
config: &Configuration{
EncryptionKey: "",
},
shouldChange: true,
Expand All @@ -91,7 +91,7 @@ func TestSetDefaults(t *testing.T) {
},
}, {
description: "set webhook key",
config: Configuration{
config: &Configuration{
WebhookSecret: "",
},
shouldChange: true,
Expand All @@ -100,7 +100,7 @@ func TestSetDefaults(t *testing.T) {
},
}, {
description: "set webhook and encryption key",
config: Configuration{
config: &Configuration{
EncryptionKey: "",
WebhookSecret: "",
},
Expand All @@ -112,7 +112,7 @@ func TestSetDefaults(t *testing.T) {
}, {
description: "Should not set UsePreregisteredApplication in on-prem",
isCloud: false,
config: Configuration{
config: &Configuration{
EncryptionKey: "abcd",
WebhookSecret: "efgh",
UsePreregisteredApplication: false,
Expand All @@ -125,7 +125,7 @@ func TestSetDefaults(t *testing.T) {
}, {
description: "Should set UsePreregisteredApplication in cloud if no OAuth secret is configured",
isCloud: true,
config: Configuration{
config: &Configuration{
EncryptionKey: "abcd",
WebhookSecret: "efgh",
UsePreregisteredApplication: false,
Expand All @@ -140,7 +140,7 @@ func TestSetDefaults(t *testing.T) {
}, {
description: "Should set not UsePreregisteredApplication in cloud if OAuth secret is configured",
isCloud: true,
config: Configuration{
config: &Configuration{
EncryptionKey: "abcd",
WebhookSecret: "efgh",
UsePreregisteredApplication: false,
Expand All @@ -160,7 +160,7 @@ func TestSetDefaults(t *testing.T) {
changed, err := testCase.config.setDefaults(testCase.isCloud)

assert.Equal(t, testCase.shouldChange, changed)
testCase.outputCheck(t, &testCase.config)
testCase.outputCheck(t, testCase.config)

if testCase.errMsg != "" {
require.Error(t, err)
Expand Down
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 36e72f4

Please sign in to comment.