@@ -5,23 +5,15 @@ import (
5
5
"context"
6
6
"fmt"
7
7
"net/http"
8
- "regexp"
9
8
"strings"
10
9
texttemplate "text/template"
11
- "unicode/utf8"
12
10
13
11
"github.com/bradleyfalzon/ghinstallation/v2"
14
12
"github.com/google/go-github/v41/github"
15
13
log "github.com/sirupsen/logrus"
16
14
"github.com/spf13/cast"
17
- giturls "github.com/whilp/git-urls"
18
15
19
16
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$` )
25
17
)
26
18
27
19
type GitHubOptions struct {
@@ -61,16 +53,16 @@ type GitHubPullRequestComment struct {
61
53
}
62
54
63
55
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}}"
66
58
)
67
59
68
60
func (g * GitHubNotification ) GetTemplater (name string , f texttemplate.FuncMap ) (Templater , error ) {
69
61
if g .RepoURLPath == "" {
70
- g .RepoURLPath = repoURLtemplate
62
+ g .RepoURLPath = githubRepoURLtemplate
71
63
}
72
64
if g .RevisionPath == "" {
73
- g .RevisionPath = revisionTemplate
65
+ g .RevisionPath = githubRevisionTemplate
74
66
}
75
67
76
68
repoURL , err := texttemplate .New (name ).Funcs (f ).Parse (g .RepoURLPath )
@@ -276,27 +268,6 @@ type gitHubService struct {
276
268
client * github.Client
277
269
}
278
270
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
-
300
271
func (g gitHubService ) Send (notification Notification , _ Destination ) error {
301
272
if notification .GitHub == nil {
302
273
return fmt .Errorf ("config is empty" )
0 commit comments