From 695f66327ea5acdea58b0d186a8e80447e3a35d1 Mon Sep 17 00:00:00 2001 From: Carlotta Fabian Date: Wed, 18 Dec 2024 17:50:01 +0100 Subject: [PATCH 1/4] update xanzy repo to the one that is maintained --- command/pullrequest/gitlab_test.go | 2 +- go.mod | 6 +++--- go.sum | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/command/pullrequest/gitlab_test.go b/command/pullrequest/gitlab_test.go index a9f59fee..b2a2e5df 100644 --- a/command/pullrequest/gitlab_test.go +++ b/command/pullrequest/gitlab_test.go @@ -11,7 +11,7 @@ import ( "github.com/innogames/slack-bot/v2/mocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/xanzy/go-gitlab" + "gitlab.com/gitlab-org/api/client-go" ) func TestGitlab(t *testing.T) { diff --git a/go.mod b/go.mod index 92abe339..af72c375 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/innogames/slack-bot/v2 -go 1.22.0 +go 1.23.4 require ( github.com/alicebob/miniredis/v2 v2.33.0 @@ -22,7 +22,7 @@ require ( github.com/slack-go/slack v0.15.0 github.com/stretchr/testify v1.10.0 github.com/texttheater/golang-levenshtein/levenshtein v0.0.0-20200805054039-cae8b0eaed6c - github.com/xanzy/go-gitlab v0.115.0 + gitlab.com/gitlab-org/api/client-go v0.117.0 golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f golang.org/x/oauth2 v0.24.0 golang.org/x/text v0.21.0 @@ -67,7 +67,7 @@ require ( golang.org/x/net v0.31.0 // indirect golang.org/x/sys v0.27.0 // indirect golang.org/x/time v0.8.0 // indirect - google.golang.org/protobuf v1.35.2 // indirect + google.golang.org/protobuf v1.36.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 4e30b189..71670de3 100644 --- a/go.sum +++ b/go.sum @@ -305,8 +305,6 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1 github.com/trivago/tgo v1.0.7 h1:uaWH/XIy9aWYWpjm2CU3RpcqZXmX2ysQ9/Go+d9gyrM= github.com/trivago/tgo v1.0.7/go.mod h1:w4dpD+3tzNIIiIfkWWa85w5/B77tlvdZckQ+6PkFnhc= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/xanzy/go-gitlab v0.115.0 h1:6DmtItNcVe+At/liXSgfE/DZNZrGfalQmBRmOcJjOn8= -github.com/xanzy/go-gitlab v0.115.0/go.mod h1:5XCDtM7AM6WMKmfDdOiEpyRWUqui2iS9ILfvCZ2gJ5M= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= @@ -314,6 +312,8 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1: github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M= github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= +gitlab.com/gitlab-org/api/client-go v0.117.0 h1:HsbKxlTjVgfYmyCU+NRQk2G42RlMOKs6gF+/o0DL+TI= +gitlab.com/gitlab-org/api/client-go v0.117.0/go.mod h1:E+X2dndIYDuUfKVP0C3jhkWvTSE00BkLbCsXTY3edDo= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= @@ -476,8 +476,8 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= -google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= +google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 0b81efa817a6023e5e1b87e3e754f282233eb2ee Mon Sep 17 00:00:00 2001 From: Carlotta Fabian Date: Wed, 18 Dec 2024 17:54:37 +0100 Subject: [PATCH 2/4] gitlab: if someone is assigned as reviewer the eyes are displayed in slack --- command/pullrequest/gitlab.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/command/pullrequest/gitlab.go b/command/pullrequest/gitlab.go index 17d844e2..d9cfab86 100644 --- a/command/pullrequest/gitlab.go +++ b/command/pullrequest/gitlab.go @@ -1,16 +1,15 @@ package pullrequest import ( - "regexp" - "strings" - "text/template" - "github.com/innogames/slack-bot/v2/bot" "github.com/innogames/slack-bot/v2/bot/config" "github.com/innogames/slack-bot/v2/bot/matcher" "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/xanzy/go-gitlab" + "gitlab.com/gitlab-org/api/client-go" + "regexp" + "strings" + "text/template" ) type gitlabFetcher struct { @@ -63,11 +62,17 @@ func (c *gitlabFetcher) getPullRequest(match matcher.Result) (pullRequest, error func (c *gitlabFetcher) getStatus(pr *gitlab.MergeRequest) prStatus { // https://docs.gitlab.com/ce/api/merge_requests.html - switch pr.State { - case "merged": + var inReview = false + if len(pr.Reviewers) > 0 { + inReview = true + } + switch { + case pr.State == "merged": return prStatusMerged - case "closed", "locked": + case pr.State == "closed" || pr.State == "locked": return prStatusClosed + case inReview: + return prStatusInReview default: return prStatusOpen } From 74aa6a6d446ef2297e5e2cbc65247c2811ba7911 Mon Sep 17 00:00:00 2001 From: Carlotta Fabian Date: Thu, 19 Dec 2024 12:53:06 +0100 Subject: [PATCH 3/4] add test --- command/pullrequest/gitlab.go | 9 +++++---- command/pullrequest/gitlab_test.go | 11 ++++++++++- go.mod | 6 +++--- go.sum | 8 ++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/command/pullrequest/gitlab.go b/command/pullrequest/gitlab.go index d9cfab86..c7dfd18e 100644 --- a/command/pullrequest/gitlab.go +++ b/command/pullrequest/gitlab.go @@ -1,15 +1,16 @@ package pullrequest import ( + "regexp" + "strings" + "text/template" + "github.com/innogames/slack-bot/v2/bot" "github.com/innogames/slack-bot/v2/bot/config" "github.com/innogames/slack-bot/v2/bot/matcher" "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "gitlab.com/gitlab-org/api/client-go" - "regexp" - "strings" - "text/template" + "github.com/xanzy/go-gitlab" ) type gitlabFetcher struct { diff --git a/command/pullrequest/gitlab_test.go b/command/pullrequest/gitlab_test.go index b2a2e5df..6d82cd57 100644 --- a/command/pullrequest/gitlab_test.go +++ b/command/pullrequest/gitlab_test.go @@ -11,7 +11,7 @@ import ( "github.com/innogames/slack-bot/v2/mocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/api/client-go" + "github.com/xanzy/go-gitlab" ) func TestGitlab(t *testing.T) { @@ -51,6 +51,15 @@ func TestGitlab(t *testing.T) { mr.State = "closed" actual = gitlabFetcher.getStatus(mr) assert.Equal(t, prStatusClosed, actual) + + mr = &gitlab.MergeRequest{} + mr.Reviewers = []*gitlab.BasicUser{ + { + Username: "user", + }, + } + actual = gitlabFetcher.getStatus(mr) + assert.Equal(t, prStatusInReview, actual) }) t.Run("test convertToPullRequest", func(t *testing.T) { diff --git a/go.mod b/go.mod index af72c375..92abe339 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/innogames/slack-bot/v2 -go 1.23.4 +go 1.22.0 require ( github.com/alicebob/miniredis/v2 v2.33.0 @@ -22,7 +22,7 @@ require ( github.com/slack-go/slack v0.15.0 github.com/stretchr/testify v1.10.0 github.com/texttheater/golang-levenshtein/levenshtein v0.0.0-20200805054039-cae8b0eaed6c - gitlab.com/gitlab-org/api/client-go v0.117.0 + github.com/xanzy/go-gitlab v0.115.0 golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f golang.org/x/oauth2 v0.24.0 golang.org/x/text v0.21.0 @@ -67,7 +67,7 @@ require ( golang.org/x/net v0.31.0 // indirect golang.org/x/sys v0.27.0 // indirect golang.org/x/time v0.8.0 // indirect - google.golang.org/protobuf v1.36.0 // indirect + google.golang.org/protobuf v1.35.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 71670de3..4e30b189 100644 --- a/go.sum +++ b/go.sum @@ -305,6 +305,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1 github.com/trivago/tgo v1.0.7 h1:uaWH/XIy9aWYWpjm2CU3RpcqZXmX2ysQ9/Go+d9gyrM= github.com/trivago/tgo v1.0.7/go.mod h1:w4dpD+3tzNIIiIfkWWa85w5/B77tlvdZckQ+6PkFnhc= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/xanzy/go-gitlab v0.115.0 h1:6DmtItNcVe+At/liXSgfE/DZNZrGfalQmBRmOcJjOn8= +github.com/xanzy/go-gitlab v0.115.0/go.mod h1:5XCDtM7AM6WMKmfDdOiEpyRWUqui2iS9ILfvCZ2gJ5M= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= @@ -312,8 +314,6 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1: github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M= github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= -gitlab.com/gitlab-org/api/client-go v0.117.0 h1:HsbKxlTjVgfYmyCU+NRQk2G42RlMOKs6gF+/o0DL+TI= -gitlab.com/gitlab-org/api/client-go v0.117.0/go.mod h1:E+X2dndIYDuUfKVP0C3jhkWvTSE00BkLbCsXTY3edDo= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= @@ -476,8 +476,8 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= -google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= +google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 044acf24f0dd37ba3ad944319916cfd048876255 Mon Sep 17 00:00:00 2001 From: Carlotta Fabian Date: Thu, 19 Dec 2024 13:03:54 +0100 Subject: [PATCH 4/4] fmt --- command/pullrequest/gitlab.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/pullrequest/gitlab.go b/command/pullrequest/gitlab.go index c7dfd18e..4089bc9e 100644 --- a/command/pullrequest/gitlab.go +++ b/command/pullrequest/gitlab.go @@ -63,7 +63,7 @@ func (c *gitlabFetcher) getPullRequest(match matcher.Result) (pullRequest, error func (c *gitlabFetcher) getStatus(pr *gitlab.MergeRequest) prStatus { // https://docs.gitlab.com/ce/api/merge_requests.html - var inReview = false + inReview := false if len(pr.Reviewers) > 0 { inReview = true }