-
Notifications
You must be signed in to change notification settings - Fork 0
/
squash.go
50 lines (40 loc) · 1.46 KB
/
squash.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
package main
import (
"net/url"
"regexp"
"github.com/sirupsen/logrus"
)
var (
regAddSquash = regexp.MustCompile(`(?mi)^/squash\s*$`)
regRemoveSquash = regexp.MustCompile(`(?mi)^/squash cancel\s*$`)
)
const squashLabel = "merge/squash"
func (bot *robot) handledSquash(comment, commenter, org, repo, number string) error {
if regAddSquash.MatchString(comment) {
return bot.addSquash(commenter, org, repo, number)
}
if regRemoveSquash.MatchString(comment) {
return bot.removedSquash(commenter, org, repo, number)
}
return nil
}
func (bot *robot) addSquash(commenter, org, repo, number string) error {
logrus.Infof("addSquash, commenter: %s, org: %s, repo: %s, number: %s", commenter, org, repo, number)
if pass, ok := bot.cli.CheckPermission(org, repo, commenter); pass && ok {
label := bot.getPRLabelSet(org, repo, number)
if _, ok := label[rebaseLabel]; ok {
bot.cli.CreatePRComment(org, repo, number,
"Please use **/rebase cancel** to remove **merge/rebase** label, and try **/squash** again")
return nil
}
bot.cli.AddPRLabels(org, repo, number, []string{squashLabel})
}
return nil
}
func (bot *robot) removedSquash(commenter, org, repo, number string) error {
logrus.Infof("removedSquash, commenter: %s, org: %s, repo: %s, number: %s", commenter, org, repo, number)
if pass, ok := bot.cli.CheckPermission(org, repo, commenter); pass && ok {
bot.cli.RemovePRLabels(org, repo, number, []string{url.QueryEscape(squashLabel)})
}
return nil
}