-
Notifications
You must be signed in to change notification settings - Fork 1
/
command.go
78 lines (62 loc) · 1.46 KB
/
command.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
package input
import (
"log"
"strings"
)
// ParseCommand is doing adhoc command parsing.
// for the future, we should write an actual parser.
func ParseCommand(raw string) (ok bool, cmd interface{}) {
log.Printf("debug: input: %v\n", raw)
tmp := strings.Split(raw, "\n")
// If there are no possibility that the comment body is not formatted
// `@botname command`, stop to process.
if len(tmp) < 1 {
return false, nil
}
for index := range tmp {
if strings.Index(tmp[index], "@") != -1 {
body := tmp[index]
log.Printf("debug: body: %v\n", body)
r := strings.NewReader(body)
p := newParser(r)
cmd, err := p.Parse()
if err != nil {
log.Printf("debug: parse error: %v\n", err)
return false, nil
}
return true, cmd
}
}
return false, nil
}
type AcceptChangesetCommand interface {
BotName() string
}
type AcceptChangeByReviewerCommand struct {
botName string
}
func (s *AcceptChangeByReviewerCommand) BotName() string {
return s.botName
}
type AcceptChangeByOthersCommand struct {
botName string
Reviewer []string
}
func (s *AcceptChangeByOthersCommand) BotName() string {
return s.botName
}
type AcceptChangeOnReview struct {
BotNameForReview string
}
func (s *AcceptChangeOnReview) BotName() string {
return s.BotNameForReview
}
type AssignReviewerCommand struct {
Reviewer []string
}
type CancelApprovedByReviewerCommand struct {
botName string
}
func (s *CancelApprovedByReviewerCommand) BotName() string {
return s.botName
}