generated from tidb-incubator/tidb-template-project
-
Notifications
You must be signed in to change notification settings - Fork 13
/
event.go
52 lines (43 loc) · 1.1 KB
/
event.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
package addTemplate
import (
"fmt"
"github.com/google/go-github/v32/github"
"github.com/pingcap-incubator/cherry-bot/util"
"github.com/pkg/errors"
"io/ioutil"
)
func (c *Comment) ProcessIssueCommentEvent(event *github.IssueCommentEvent) {
if event.GetAction() != "created" {
return
}
if err := c.processComment(event, event.Comment.GetBody()); err != nil {
util.Error(err)
}
}
func (c *Comment) processComment(event *github.IssueCommentEvent, comment string) error {
issueID := event.GetIssue().GetNumber()
fmt.Println(issueID)
if comment == "/info" {
e := c.addTemplate(issueID)
if e != nil {
err := errors.Wrap(e, "add template to comment fail")
return err
}
}
return nil
}
func (c *Comment) addTemplate(issueID int) (err error) {
b, e := ioutil.ReadFile("/root/github-bot/bug_template.txt")
if e != nil {
err = errors.Wrap(e, "read bug template file failed")
return err
}
template := string(b)
//fmt.Println(template)
e = c.opr.CommentOnGithub(c.owner, c.repo, issueID, template)
if e != nil {
err = errors.Wrap(e, "add template failed")
return err
}
return nil
}