forked from review-robot/robot-gitee-label
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquash.go
More file actions
30 lines (23 loc) · 768 Bytes
/
Copy pathsquash.go
File metadata and controls
30 lines (23 loc) · 768 Bytes
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
package main
import sdk "github.com/opensourceways/go-gitee/gitee"
func (bot *robot) handleSquashLabel(e *sdk.PullRequestEvent, commits uint, cfg SquashConfig) error {
if cfg.unableCheckingSquash() {
return nil
}
action := sdk.GetPullRequestAction(e)
if action != sdk.ActionOpen && action != sdk.PRActionChangedSourceBranch {
return nil
}
labels := e.GetPRLabelSet()
hasSquashLabel := labels.Has(cfg.SquashCommitLabel)
exceeded := commits > cfg.CommitsThreshold
org, repo := e.GetOrgRepo()
number := e.GetPRNumber()
if exceeded && !hasSquashLabel {
return bot.cli.AddPRLabel(org, repo, number, cfg.SquashCommitLabel)
}
if !exceeded && hasSquashLabel {
return bot.cli.RemovePRLabel(org, repo, number, cfg.SquashCommitLabel)
}
return nil
}