Skip to content

Commit 1b19de2

Browse files
authored
feat: add gitlab service
Signed-off-by: GitHub <noreply@github.com>
1 parent a8d185e commit 1b19de2

9 files changed

+640
-38
lines changed

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require (
2424
github.com/spf13/cobra v1.6.1
2525
github.com/stretchr/testify v1.8.4
2626
github.com/whilp/git-urls v0.0.0-20191001220047-6db9661140c0
27+
github.com/xanzy/go-gitlab v0.93.2
2728
golang.org/x/time v0.3.0
2829
gomodules.xyz/notify v0.1.1
2930
google.golang.org/api v0.132.0
@@ -113,7 +114,7 @@ require (
113114
github.com/aws/aws-sdk-go-v2 v1.17.3
114115
github.com/aws/aws-sdk-go-v2/config v1.18.8
115116
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
116-
github.com/hashicorp/go-retryablehttp v0.5.3
117+
github.com/hashicorp/go-retryablehttp v0.7.2
117118
)
118119

119120
replace github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.14.0

go.sum

+6-2
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,11 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb
289289
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
290290
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
291291
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
292+
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
293+
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
292294
github.com/hashicorp/go-retryablehttp v0.5.1/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
293-
github.com/hashicorp/go-retryablehttp v0.5.3 h1:QlWt0KvWT0lq8MFppF9tsJGF+ynG7ztc2KIPhzRGk7s=
294-
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
295+
github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=
296+
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
295297
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
296298
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
297299
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
@@ -439,6 +441,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
439441
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
440442
github.com/whilp/git-urls v0.0.0-20191001220047-6db9661140c0 h1:qqllXPzXh+So+mmANlX/gCJrgo+1kQyshMoQ+NASzm0=
441443
github.com/whilp/git-urls v0.0.0-20191001220047-6db9661140c0/go.mod h1:2rx5KE5FLD0HRfkkpyn8JwbVLBdhgeiOb2D2D9LLKM4=
444+
github.com/xanzy/go-gitlab v0.93.2 h1:kNNf3BYNYn/Zkig0B89fma12l36VLcYSGu7OnaRlRDg=
445+
github.com/xanzy/go-gitlab v0.93.2/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw=
442446
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
443447
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
444448
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

pkg/services/github.go

+4-33
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,15 @@ import (
55
"context"
66
"fmt"
77
"net/http"
8-
"regexp"
98
"strings"
109
texttemplate "text/template"
11-
"unicode/utf8"
1210

1311
"github.com/bradleyfalzon/ghinstallation/v2"
1412
"github.com/google/go-github/v41/github"
1513
log "github.com/sirupsen/logrus"
1614
"github.com/spf13/cast"
17-
giturls "github.com/whilp/git-urls"
1815

1916
httputil "github.com/argoproj/notifications-engine/pkg/util/http"
20-
"github.com/argoproj/notifications-engine/pkg/util/text"
21-
)
22-
23-
var (
24-
gitSuffix = regexp.MustCompile(`\.git$`)
2517
)
2618

2719
type GitHubOptions struct {
@@ -61,16 +53,16 @@ type GitHubPullRequestComment struct {
6153
}
6254

6355
const (
64-
repoURLtemplate = "{{.app.spec.source.repoURL}}"
65-
revisionTemplate = "{{.app.status.operationState.syncResult.revision}}"
56+
githubRepoURLtemplate = "{{.app.spec.source.repoURL}}"
57+
githubRevisionTemplate = "{{.app.status.operationState.syncResult.revision}}"
6658
)
6759

6860
func (g *GitHubNotification) GetTemplater(name string, f texttemplate.FuncMap) (Templater, error) {
6961
if g.RepoURLPath == "" {
70-
g.RepoURLPath = repoURLtemplate
62+
g.RepoURLPath = githubRepoURLtemplate
7163
}
7264
if g.RevisionPath == "" {
73-
g.RevisionPath = revisionTemplate
65+
g.RevisionPath = githubRevisionTemplate
7466
}
7567

7668
repoURL, err := texttemplate.New(name).Funcs(f).Parse(g.RepoURLPath)
@@ -276,27 +268,6 @@ type gitHubService struct {
276268
client *github.Client
277269
}
278270

279-
func trunc(message string, n int) string {
280-
if utf8.RuneCountInString(message) > n {
281-
return string([]rune(message)[0:n-3]) + "..."
282-
}
283-
return message
284-
}
285-
286-
func fullNameByRepoURL(rawURL string) string {
287-
parsed, err := giturls.Parse(rawURL)
288-
if err != nil {
289-
panic(err)
290-
}
291-
292-
path := gitSuffix.ReplaceAllString(parsed.Path, "")
293-
if pathParts := text.SplitRemoveEmpty(path, "/"); len(pathParts) >= 2 {
294-
return strings.Join(pathParts[:2], "/")
295-
}
296-
297-
return path
298-
}
299-
300271
func (g gitHubService) Send(notification Notification, _ Destination) error {
301272
if notification.GitHub == nil {
302273
return fmt.Errorf("config is empty")

pkg/services/github_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func TestNewGitHubService_GitHubOptions(t *testing.T) {
213213
}
214214
}
215215

216-
func TestGetTemplater_Github_PullRequestComment(t *testing.T) {
216+
func TestGetTemplater_GitHub_PullRequestComment(t *testing.T) {
217217
n := Notification{
218218
GitHub: &GitHubNotification{
219219
RepoURLPath: "{{.sync.spec.git.repo}}",

0 commit comments

Comments
 (0)