forked from zengchen1024/robot-gitee-review-trigger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
review_config.go
90 lines (71 loc) · 2.45 KB
/
review_config.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
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"fmt"
"regexp"
"k8s.io/apimachinery/pkg/util/sets"
)
type ownerConfig struct {
// BranchWithoutOwners is a list of branches which have no OWNERS file
// For these branch, collaborators will work as the approvers
// It can't be set with BranchWithOwners at same time
BranchWithoutOwners string `json:"branch_without_owners"`
reBranchWithoutOwners *regexp.Regexp
// BranchWithOwners is a list of branches which have OWNERS file
// It can't be set with BranchWithoutOwners at same time
BranchWithOwners []string `json:"branch_with_owners"`
}
func (o *ownerConfig) setDefault() {}
func (o *ownerConfig) validate() error {
if o == nil {
return nil
}
if len(o.BranchWithOwners) > 0 && o.BranchWithoutOwners != "" {
return fmt.Errorf("both `branch_with_owners` and `branch_without_owners` can not be set at same time")
}
if o.BranchWithoutOwners != "" {
r, err := regexp.Compile(o.BranchWithoutOwners)
if err != nil {
return fmt.Errorf("the value of `branch_without_owners` is not a valid regexp, err:%v", err)
}
o.reBranchWithoutOwners = r
}
return nil
}
// len(o.BranchWithOwners) == 0 && o.BranchWithoutOwners == "" means all branch has OWNERS file.
func (o ownerConfig) IsBranchWithoutOwners(branch string) bool {
if len(o.BranchWithOwners) > 0 {
return !sets.NewString(o.BranchWithOwners...).Has(branch)
}
return o.reBranchWithoutOwners != nil && o.reBranchWithoutOwners.MatchString(branch)
}
type reviewConfig struct {
// AllowSelfApprove is the tag which indicate if the author
// can appove his/her own pull-request.
AllowSelfApprove bool `json:"allow_self_approve"`
// NumberOfApprovers is the min number of approvers who commented
// /approve at same time to approve a single module
NumberOfApprovers int `json:"number_of_approvers"`
// TotalNumberOfApprovers is the min number of approvers who commented
// /approve at same time to add approved label
TotalNumberOfApprovers int `json:"total_number_of_approvers"`
// TotalNumberOfReviewers is the min number of reviewers who commented
// /lgtm at same time to add lgtm label
TotalNumberOfReviewers int `json:"total_number_of_reviewers"`
}
func (r reviewConfig) validate() error {
return nil
}
func (r *reviewConfig) setDefault() {
if r == nil {
return
}
if r.NumberOfApprovers <= 0 {
r.NumberOfApprovers = 1
}
if r.TotalNumberOfApprovers <= 0 {
r.TotalNumberOfApprovers = 2
}
if r.TotalNumberOfReviewers == 0 {
r.TotalNumberOfReviewers = 1
}
}