generated from tidb-incubator/tidb-template-project
-
Notifications
You must be signed in to change notification settings - Fork 13
/
webhook.go
109 lines (88 loc) · 2.71 KB
/
webhook.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
97
98
99
100
101
102
103
104
105
106
107
108
109
package bot
import (
"github.com/pingcap-incubator/cherry-bot/util"
"github.com/google/go-github/v29/github"
"github.com/pkg/errors"
)
func (b *bot) Webhook(event interface{}) {
switch event := event.(type) {
case *github.PullRequestEvent:
b.processPullRequestEvent(event)
case *github.IssueCommentEvent:
b.processIssueCommentEvent(event)
case *github.IssuesEvent:
b.processIssuesEvent(event)
case *github.PullRequestReviewEvent:
b.processPullRequestReviewEvent(event)
case *github.PullRequestReviewCommentEvent:
b.processPullRequestReviewCommentEvent(event)
}
}
func (b *bot) processPullRequestEvent(event *github.PullRequestEvent) {
switch *event.Action {
case "opened", "labeled", "unlabeled":
util.Error(errors.Wrap(b.createOrUpdatePullRequest(event.PullRequest), "bot process pull request event"))
}
if b.cfg.CherryPick {
b.Middleware.cherry.ProcessPullRequestEvent(event)
}
if b.cfg.LabelCheck {
b.Middleware.label.ProcessPullRequestEvent(event)
}
if b.cfg.PrLimit {
b.Middleware.Prlimit.ProcessPullRequestEvent(event)
}
if b.cfg.Merge {
b.Middleware.Merge.ProcessPullRequestEvent(event)
}
if b.cfg.StatusControl {
b.Middleware.PullStatus.ProcessPullRequestEvent(event)
}
if b.cfg.AutoUpdate {
b.Middleware.AutoUpdate.ProcessPullRequestEvent(event)
}
b.Middleware.Contributor.ProcessPullRequestEvent(event)
}
func (b *bot) processIssuesEvent(event *github.IssuesEvent) {
util.Println("process issue event in bot", event.GetIssue().GetNumber())
if b.cfg.IssueRedeliver {
b.Middleware.IssueRedeliver.ProcessIssuesEvent(event)
}
if b.cfg.LabelCheck {
b.Middleware.label.ProcessIssuesEvent(event)
}
if b.cfg.IssueSlackNotice {
b.Middleware.Notify.ProcessIssuesEvent(event)
}
}
func (b *bot) processIssueCommentEvent(event *github.IssueCommentEvent) {
if b.cfg.CherryPick {
b.Middleware.cherry.ProcessIssueCommentEvent(event)
}
if b.cfg.Merge {
b.Middleware.Merge.ProcessIssueCommentEvent(event)
}
if b.cfg.IssueRedeliver {
b.Middleware.IssueRedeliver.ProcessIssueCommentEvent(event)
}
if b.cfg.StatusControl {
b.Middleware.PullStatus.ProcessIssueCommentEvent(event)
}
if b.cfg.IssueSlackNotice {
b.Middleware.Notify.ProcessIssueCommentEvent(event)
}
if b.cfg.PullApprove {
b.Middleware.Approve.ProcessIssueCommentEvent(event)
}
b.Middleware.CommandRedeliver.ProcessIssueCommentEvent(event)
}
func (b *bot) processPullRequestReviewEvent(event *github.PullRequestReviewEvent) {
if b.cfg.StatusControl {
b.Middleware.PullStatus.ProcessPullRequestReviewEvent(event)
}
}
func (b *bot) processPullRequestReviewCommentEvent(event *github.PullRequestReviewCommentEvent) {
if b.cfg.StatusControl {
b.Middleware.PullStatus.ProcessPullRequestReviewCommentEvent(event)
}
}