Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

#32 jira rnd #34

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
GITLAB_TOKEN="glpat-xxxxxxxxxxxxx-xxxxxx"
SLACK_BOT_TOKEN="xoxb-000000000000-0000000000000-XXXXXXXXXXXXXXXXXXXXXXXX"
SLACK_APP_TOKEN="xapp-0-AAAAAAAAAAF-0000000000000-ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
JIRA_URL="https://mycompany.atlassian.net/"
JIRA_USERNAME="[email protected]"
JIRA_API_TOKEN="xxxxxxxxxxxxxxxxxxxxxxx"

MONGO_HOST="127.0.0.1"
MONGO_PORT="27017"
44 changes: 43 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
linters-settings:
govet:
check-shadowing: false
golint:
min-confidence: 0
goconst:
min-len: 2
min-occurrences: 2
gocritic:
disabled-checks:
- ifElseChain
nakedret:
max-func-lines: 15
goimports:
local-prefixes: gitlab.com/tabby.ai/scoring

run:
skip-dirs:
- mocks

linters:
enable:
- gocritic
- stylecheck
- goimports
- gosec
- unconvert
- unparam
- gosec
- nakedret
- whitespace
- gosimple
- bodyclose
- dogsled
disable:
- gochecknoinits
- maligned
- lll
- dupl
- gochecknoglobals

issues:
exclude:
- "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
- "exported (type|method|function) (.+) should have comment or be unexported"
- "ST1000: at least one file in a package should have a package comment"
- "composites: go.mongodb.org/mongo-driver/bson/primitive.E struct literal uses unkeyed fields"
- "composites: go.mongodb.org/mongo-driver/bson/primitive.E struct literal uses unkeyed fields"
- ST1003
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ module github.com/spatecon/gitlab-review-bot
go 1.19

require (
github.com/andygrunwald/go-jira v1.16.0
github.com/gertd/go-pluralize v0.2.1
github.com/golang/mock v1.6.0
github.com/gookit/config/v2 v2.1.8
@@ -22,6 +23,8 @@ require (
require (
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-querystring v1.1.0 // indirect
@@ -37,6 +40,7 @@ require (
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/segmentio/fasthash v1.0.3 // indirect
github.com/trivago/tgo v1.0.7 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -2,19 +2,25 @@ github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 h1:MzBOUgng9orim59UnfUTLRjMpd09C5uEVQ6RPGeCaVI=
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg=
github.com/andygrunwald/go-jira v1.16.0 h1:PU7C7Fkk5L96JvPc6vDVIrd99vdPnYudHu4ju2c2ikQ=
github.com/andygrunwald/go-jira v1.16.0/go.mod h1:UQH4IBVxIYWbgagc0LF/k9FRs9xjIiQ8hIcC6HfLwFU=
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/gertd/go-pluralize v0.2.1 h1:M3uASbVjMnTsPb0PNqg+E/24Vwigyo/tvyMTtAlLgiA=
github.com/gertd/go-pluralize v0.2.1/go.mod h1:rbYaKDbsXxmRfr8uygAEKhOWsjyrrqrkHVpZvoOp8zk=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs=
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -30,6 +36,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -110,6 +117,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
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/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
@@ -177,13 +186,15 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
1 change: 0 additions & 1 deletion internal/app/policy/reinventing-democracy/policy.go
Original file line number Diff line number Diff line change
@@ -47,7 +47,6 @@ func New(r Repository, g GitlabClient) *Policy {
r: r,
g: g,
}

}

type metadata struct {
1 change: 0 additions & 1 deletion internal/app/policy/team-lead-always-right/policy.go
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@ func New(r Repository, g GitlabClient) *Policy {
r: r,
g: g,
}

}

type metadata struct {
1 change: 0 additions & 1 deletion internal/app/service/merge_request.go
Original file line number Diff line number Diff line change
@@ -67,7 +67,6 @@ func (s *Service) mergeRequestsHandler(mr *ds.MergeRequest) error {
Str("policy", string(team.Policy)).
Msg("failed to process merge request")
}

}

return nil
1 change: 0 additions & 1 deletion internal/app/service/notification.go
Original file line number Diff line number Diff line change
@@ -120,7 +120,6 @@ func (s *Service) TeamNotification(team *ds.Team, authorToMR, reviewerToMR map[i
summary.LastEditedMR = mr
}
}

}

summary.TotalCount = len(uniqMR)
1 change: 0 additions & 1 deletion internal/app/service/worker/notification.go
Original file line number Diff line number Diff line change
@@ -89,7 +89,6 @@ func (n *Notifications) slackMessages(
devs []*ds.User,
authorToMR, reviewerToMR map[int][]*ds.MergeRequest,
) ([]SlackMessage, error) {

slackMessages := make([]SlackMessage, 0, len(devs)+1)

for _, dev := range devs {
5 changes: 1 addition & 4 deletions internal/pkg/app/app.go
Original file line number Diff line number Diff line change
@@ -57,10 +57,7 @@ func New(configPath string) (*App, error) {
return nil, errors.Wrap(err, "failed to init clients")
}

err = app.initPolicies()
if err != nil {
return nil, errors.Wrap(err, "failed to init policies")
}
app.initPolicies()

err = app.initService()
if err != nil {
4 changes: 1 addition & 3 deletions internal/pkg/app/service.go
Original file line number Diff line number Diff line change
@@ -9,13 +9,11 @@ import (
"github.com/spatecon/gitlab-review-bot/internal/app/service"
)

func (a *App) initPolicies() error {
func (a *App) initPolicies() {
a.policies = make(map[ds.PolicyName]service.Policy)

a.policies[rd.PolicyName] = rd.New(a.repository, a.gitlabClient)
a.policies[tlar.PolicyName] = tlar.New(a.repository, a.gitlabClient)

return nil
}

func (a *App) initService() error {
1 change: 1 addition & 0 deletions internal/pkg/client/jira/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package jira
43 changes: 43 additions & 0 deletions internal/pkg/client/jira/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package jira

import (
"encoding/json"
"os"
"testing"

"github.com/andygrunwald/go-jira"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
)

func TestJiraLibrary(t *testing.T) {
tp := jira.BasicAuthTransport{
Username: os.Getenv("JIRA_USERNAME"),
Password: os.Getenv("JIRA_API_TOKEN"),
}

client, err := jira.NewClient(tp.Client(), os.Getenv("JIRA_URL"))
require.NoError(t, err, "failed to create jira client")

//b, _, err := client.Board.GetBoard(71)
//require.NoError(t, err, "failed to get board")
//
//t.Log(string(lo.Must(json.MarshalIndent(b, "", " "))))
//
//bc, _, err := client.Board.GetBoardConfiguration(71)
//require.NoError(t, err, "failed to get board configuration")
//
//t.Log(string(lo.Must(json.MarshalIndent(bc, "", " "))))
//
//sprints, _, err := client.Board.GetAllSprints(strconv.Itoa(b.ID))
//require.NoError(t, err, "failed to get sprints")
//
//t.Log(string(lo.Must(json.MarshalIndent(sprints, "", " "))))

sprintID := 738

issues, _, err := client.Sprint.GetIssuesForSprint(sprintID)
require.NoError(t, err, "failed to get issues for sprint")

t.Log(string(lo.Must(json.MarshalIndent(issues, "", " "))))
}
2 changes: 1 addition & 1 deletion pkg/templating/locale.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ const (

// ParseLocale parses locale from string and returns Locale type and true if found, or Default locale and false.
func ParseLocale(locale string) (Locale, bool) {
locale = strings.Replace(locale, "-", "_", -1)
locale = strings.ReplaceAll(locale, "-", "_")
locale = strings.ToLower(locale)
locale = strings.Trim(locale, " ")

2 changes: 1 addition & 1 deletion pkg/templating/ru-RU/tools.go
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ func (t *Tools) Plural(n int, wordForms ...string) string {
return forms[2]
}

n = n % 10
n %= 10

if n == 1 {
return forms[0]