forked from review-robot/robot-gitee-openeuler-review
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.go
64 lines (48 loc) · 1.59 KB
/
actions.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
package main
import (
"fmt"
"strings"
sdk "gitee.com/openeuler/go-gitee/gitee"
"github.com/opensourceways/community-robot-lib/giteeclient"
)
const (
retestCommand = "/retest"
msgNotSetReviewer = "**@%s** Thank you for submitting a PullRequest. It is detected that you have not set a reviewer, please set a one."
)
func (bot *robot) doRetest(e *sdk.PullRequestEvent) error {
if giteeclient.GetPullRequestAction(e) != giteeclient.PRActionChangedSourceBranch {
return nil
}
pr := giteeclient.GetPRInfoByPREvent(e)
return bot.cli.CreatePRComment(pr.Org, pr.Repo, pr.Number, retestCommand)
}
func (bot *robot) checkReviewer(e *sdk.PullRequestEvent, cfg *botConfig) error {
if cfg.UnableCheckingReviewerForPR || giteeclient.GetPullRequestAction(e) != giteeclient.PRActionOpened {
return nil
}
if e.GetPullRequest() != nil && len(e.GetPullRequest().Assignees) > 0 {
return nil
}
pr := giteeclient.GetPRInfoByPREvent(e)
return bot.cli.CreatePRComment(pr.Org, pr.Repo, pr.Number, fmt.Sprintf(msgNotSetReviewer, pr.Author))
}
func (bot *robot) clearLabel(e *sdk.PullRequestEvent) error {
if giteeclient.GetPullRequestAction(e) != giteeclient.PRActionChangedSourceBranch {
return nil
}
pr := giteeclient.GetPRInfoByPREvent(e)
v := getLGTMLabelsOnPR(pr.Labels)
if pr.Labels.Has(approvedLabel) {
v = append(v, approvedLabel)
}
if len(v) > 0 {
if err := bot.cli.RemovePRLabels(pr.Org, pr.Repo, pr.Number, v); err != nil {
return err
}
return bot.cli.CreatePRComment(
pr.Org, pr.Repo, pr.Number,
fmt.Sprintf(commentClearLabel, strings.Join(v, ", ")),
)
}
return nil
}