-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
105 lines (81 loc) · 2.46 KB
/
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
libconfig "github.com/opensourceways/community-robot-lib/config"
)
type pullRequestMergeMethod string
const (
mergeMethodeMerge pullRequestMergeMethod = "merge"
mergeMethodSquash pullRequestMergeMethod = "squash"
)
type configuration struct {
ConfigItems []botConfig `json:"config_items,omitempty"`
}
func (c *configuration) configFor(org, repo string) *botConfig {
if c == nil {
return nil
}
items := c.ConfigItems
v := make([]libconfig.IPluginForRepo, len(items))
for i := range items {
v[i] = &items[i]
}
if i := libconfig.FindConfig(org, repo, v); i >= 0 {
return &items[i]
}
return nil
}
func (c *configuration) Validate() error {
if c == nil {
return nil
}
items := c.ConfigItems
for i := range items {
if err := items[i].validate(); err != nil {
return err
}
}
return nil
}
func (c *configuration) SetDefault() {
if c == nil {
return
}
Items := c.ConfigItems
for i := range Items {
Items[i].setDefault()
}
}
type botConfig struct {
libconfig.PluginForRepo
// LgtmCountsRequired specifies the number of lgtm label which will be need for the pr.
// When it is greater than 1, the lgtm label is composed of 'lgtm-login'.
// The default value is 1 which means the lgtm label is itself.
LgtmCountsRequired uint `json:"lgtm_counts_required,omitempty"`
// ReposOfSig specifies the repos for which it should check the devepler's permission
// besed on the owners file in sig directory when the developer comment /lgtm or /approve
// command. The format is 'org/repo'.
ReposOfSig []string `json:"repos_of_sig,omitempty"`
// LabelsForMerge specifies the labels except approved and lgtm relevant labels
// that must be available to merge pr
LabelsForMerge []string `json:"labels_for_merge,omitempty"`
// MissingLabelsForMerge specifies the ones which a PR must not have to be merged.
MissingLabelsForMerge []string `json:"missing_labels_for_merge,omitempty"`
// MergeMethod is the method to merge PR.
// The default method of merge. Valid options are squash and merge.
MergeMethod pullRequestMergeMethod `json:"merge_method,omitempty"`
}
func (c *botConfig) setDefault() {
if c.LgtmCountsRequired == 0 {
c.LgtmCountsRequired = 1
}
if c.MergeMethod == "" {
c.MergeMethod = mergeMethodeMerge
}
}
func (c *botConfig) validate() error {
if m := c.MergeMethod; m != mergeMethodeMerge && m != mergeMethodSquash {
return fmt.Errorf("unsupported merge method:%s", m)
}
return c.PluginForRepo.Validate()
}