-
Notifications
You must be signed in to change notification settings - Fork 65
/
config.go
101 lines (83 loc) · 2.77 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
package config
import (
"fmt"
"strings"
"github.com/ejoffe/rake"
"github.com/ejoffe/spr/github/githubclient/gen/genclient"
)
type Config struct {
Repo *RepoConfig
User *UserConfig
State *InternalState
}
// Config object to hold spr configuration
type RepoConfig struct {
GitHubRepoOwner string `yaml:"githubRepoOwner"`
GitHubRepoName string `yaml:"githubRepoName"`
GitHubHost string `default:"github.com" yaml:"githubHost"`
GitHubRemote string `default:"origin" yaml:"githubRemote"`
GitHubBranch string `default:"main" yaml:"githubBranch"`
RequireChecks bool `default:"true" yaml:"requireChecks"`
RequireApproval bool `default:"true" yaml:"requireApproval"`
MergeMethod string `default:"rebase" yaml:"mergeMethod"`
MergeQueue bool `default:"false" yaml:"mergeQueue"`
PRTemplatePath string `yaml:"prTemplatePath,omitempty"`
PRTemplateInsertStart string `yaml:"prTemplateInsertStart,omitempty"`
PRTemplateInsertEnd string `yaml:"prTemplateInsertEnd,omitempty"`
MergeCheck string `yaml:"mergeCheck,omitempty"`
ForceFetchTags bool `default:"false" yaml:"forceFetchTags"`
}
type UserConfig struct {
ShowPRLink bool `default:"true" yaml:"showPRLink"`
LogGitCommands bool `default:"true" yaml:"logGitCommands"`
LogGitHubCalls bool `default:"true" yaml:"logGitHubCalls"`
StatusBitsHeader bool `default:"true" yaml:"statusBitsHeader"`
StatusBitsEmojis bool `default:"true" yaml:"statusBitsEmojis"`
CreateDraftPRs bool `default:"false" yaml:"createDraftPRs"`
PreserveTitleAndBody bool `default:"false" yaml:"preserveTitleAndBody"`
NoRebase bool `default:"false" yaml:"noRebase"`
}
type InternalState struct {
MergeCheckCommit map[string]string `yaml:"mergeCheckCommit"`
Stargazer bool `default:"false" yaml:"stargazer"`
RunCount int `default:"0" yaml:"runcount"`
}
func EmptyConfig() *Config {
return &Config{
Repo: &RepoConfig{},
User: &UserConfig{},
State: &InternalState{
MergeCheckCommit: map[string]string{},
},
}
}
func DefaultConfig() *Config {
cfg := EmptyConfig()
rake.LoadSources(cfg.Repo,
rake.DefaultSource(),
)
rake.LoadSources(cfg.User,
rake.DefaultSource(),
)
cfg.User.LogGitCommands = false
cfg.User.LogGitHubCalls = false
return cfg
}
func (c Config) MergeMethod() (genclient.PullRequestMergeMethod, error) {
var mergeMethod genclient.PullRequestMergeMethod
var err error
switch strings.ToLower(c.Repo.MergeMethod) {
case "merge":
mergeMethod = genclient.PullRequestMergeMethod_MERGE
case "squash":
mergeMethod = genclient.PullRequestMergeMethod_SQUASH
case "rebase", "":
mergeMethod = genclient.PullRequestMergeMethod_REBASE
default:
err = fmt.Errorf(
`unknown merge method %q, choose from "merge", "squash", or "rebase"`,
c.Repo.MergeMethod,
)
}
return mergeMethod, err
}