/
issue.go
77 lines (67 loc) · 2.29 KB
/
issue.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
package handlers
import (
"encoding/json"
"github.com/huawei-cloudnative/ci-bot/handlers/approve"
"github.com/huawei-cloudnative/ci-bot/handlers/assign"
"github.com/huawei-cloudnative/ci-bot/handlers/label"
"github.com/huawei-cloudnative/ci-bot/handlers/lgtm"
"github.com/huawei-cloudnative/ci-bot/handlers/repository"
"github.com/huawei-cloudnative/ci-bot/handlers/retest"
"github.com/golang/glog"
"github.com/google/go-github/github"
)
type GithubIssue github.Issue
func (s *Server) handleIssueEvent(body []byte) {
glog.Info("Received an Issue Event")
}
//function to handle issue comments
func (s *Server) handleIssueCommentEvent(body []byte, client *github.Client, r repository.Interface) {
var commentEvent github.IssueCommentEvent
// Unmarshal
err := json.Unmarshal(body, &commentEvent)
if err != nil {
glog.Errorf("Failed to unmarshal commentEvent: %v", err)
}
// label
if label.RegAddLabel.MatchString(*commentEvent.Comment.Body) || label.RegRemoveLabel.MatchString(*commentEvent.Comment.Body) {
err = label.Handle(client, commentEvent)
if err != nil {
glog.Errorf("Failed to handle label: %v", err)
}
}
// assign
if AssignOrUnassing.MatchString(*commentEvent.Comment.Body) {
err = assign.Handle(client, commentEvent)
if err != nil {
glog.Errorf("Failed to handle assign: %v", err)
}
}
// retest
if TestReg.MatchString(*commentEvent.Comment.Body) || RetestReg.MatchString(*commentEvent.Comment.Body) {
err = retest.Handle(client, commentEvent, s.Config.TravisCIToken, s.Config.TravisRepoName)
if err != nil {
glog.Errorf("Failed to handle retest: %v", err)
}
}
// approve
if approve.RegAddApprove.MatchString(*commentEvent.Comment.Body) || approve.RegCancelApprove.MatchString(*commentEvent.Comment.Body) {
err = approve.Handle(client, r, commentEvent)
if err != nil {
glog.Errorf("Failed to handle: %v", err)
}
}
// lgtm
if lgtm.RegAddLgtm.MatchString(*commentEvent.Comment.Body) || lgtm.RegCancelLgtm.MatchString(*commentEvent.Comment.Body) {
err = lgtm.Handle(client, r, commentEvent)
if err != nil {
glog.Errorf("Failed to handle: %v", err)
}
}
// reviewers
if assign.CCRegExp.MatchString(*commentEvent.Comment.Body) {
err = assign.ReviewerReqByComment(client, commentEvent)
if err != nil {
glog.Errorf("Failed to handle: %v", err)
}
}
}