forked from kubernetes/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrigger.go
96 lines (79 loc) · 2.69 KB
/
trigger.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package trigger
import (
"fmt"
"github.com/Sirupsen/logrus"
"k8s.io/test-infra/prow/config"
"k8s.io/test-infra/prow/github"
"k8s.io/test-infra/prow/kube"
"k8s.io/test-infra/prow/plugins"
)
const (
pluginName = "trigger"
lgtmLabel = "lgtm"
)
func init() {
plugins.RegisterIssueCommentHandler(pluginName, handleIssueComment)
plugins.RegisterPullRequestHandler(pluginName, handlePullRequest)
plugins.RegisterPushEventHandler(pluginName, handlePush)
}
type githubClient interface {
AddLabel(org, repo string, number int, label string) error
BotName() string
IsMember(org, user string) (bool, error)
GetPullRequest(org, repo string, number int) (*github.PullRequest, error)
GetRef(org, repo, ref string) (string, error)
CreateComment(owner, repo string, number int, comment string) error
ListIssueComments(owner, repo string, issue int) ([]github.IssueComment, error)
CreateStatus(owner, repo, ref string, status github.Status) error
GetCombinedStatus(org, repo, ref string) (*github.CombinedStatus, error)
GetPullRequestChanges(org, repo string, number int) ([]github.PullRequestChange, error)
RemoveLabel(org, repo string, number int, label string) error
}
type kubeClient interface {
CreateProwJob(kube.ProwJob) (kube.ProwJob, error)
}
type client struct {
GitHubClient githubClient
KubeClient kubeClient
Config *config.Config
Logger *logrus.Entry
}
func triggerConfig(c *config.Config, org, repo string) *config.Trigger {
for _, tr := range c.Triggers {
for _, r := range tr.Repos {
if r == org || r == fmt.Sprintf("%s/%s", org, repo) {
return &tr
}
}
}
return nil
}
func getClient(pc plugins.PluginClient) client {
return client{
GitHubClient: pc.GitHubClient,
Config: pc.Config,
KubeClient: pc.KubeClient,
Logger: pc.Logger,
}
}
func handlePullRequest(pc plugins.PluginClient, pr github.PullRequestEvent) error {
return handlePR(getClient(pc), pr)
}
func handleIssueComment(pc plugins.PluginClient, ic github.IssueCommentEvent) error {
return handleIC(getClient(pc), ic)
}
func handlePush(pc plugins.PluginClient, pe github.PushEvent) error {
return handlePE(getClient(pc), pe)
}