/
github.go
71 lines (59 loc) · 1.96 KB
/
github.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package scm
import (
"net/url"
"strings"
"github.com/redhat-developer/kam/pkg/pipelines/triggers"
triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
)
const (
githubPushEventFilters = "(header.match('X-GitHub-Event', 'push') && body.repository.full_name == '%s')"
githubType = "github"
)
type githubSpec struct {
pushBinding string
}
func init() {
gits[githubType] = newGitHub
}
func newGitHub(rawURL string) (Repository, error) {
path, err := processRawURL(rawURL, proccessGitHubPath)
if err != nil {
return nil, err
}
return &repository{url: rawURL, path: path, spec: &githubSpec{pushBinding: "github-push-binding"}}, nil
}
func proccessGitHubPath(parsedURL *url.URL) (string, error) {
components, err := splitRepositoryPath(parsedURL)
if err != nil {
return "", err
}
if len(components) != 2 {
return "", invalidRepoPathError(githubType, parsedURL.Path)
}
path := strings.Join(components, "/")
return path, nil
}
func (r *githubSpec) pushBindingName() string {
return r.pushBinding
}
func (r *githubSpec) pushBindingParams() []triggersv1.Param {
return []triggersv1.Param{
createBindingParam("gitrepositoryurl", "$(body.repository.clone_url)"),
createBindingParam("fullname", "$(body.repository.full_name)"),
createBindingParam(triggers.GitRef, "$(extensions.ref)"),
createBindingParam(triggers.GitCommitID, "$(body.head_commit.id)"),
createBindingParam(triggers.GitCommitDate, "$(body.head_commit.timestamp)"),
createBindingParam(triggers.GitCommitMessage, "$(body.head_commit.message)"),
createBindingParam(triggers.GitCommitAuthor, "$(body.head_commit.author.name)"),
}
}
func (r *githubSpec) pushEventFilters() string {
return githubPushEventFilters
}
func (r *githubSpec) eventInterceptor(secretNamespace, secretName string) (*triggersv1.EventInterceptor, error) {
raw, err := secretParam(secretName, webhookSecretKey)
if err != nil {
return nil, err
}
return eventInterceptorWithSecret(githubType, raw), nil
}