/
config.go
92 lines (73 loc) · 2.27 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
package github
import (
// Internal
"github.com/salsaflow/salsaflow/config/loader"
"github.com/salsaflow/salsaflow/prompt"
)
// Configuration ===============================================================
type moduleConfig struct {
Token string
ReviewLabel string
StoryImplementedLabel string
}
func loadConfig() (*moduleConfig, error) {
spec := newConfigSpec()
if err := loader.LoadConfig(spec); err != nil {
return nil, err
}
return &moduleConfig{
Token: spec.global.Token,
ReviewLabel: spec.local.ReviewLabel,
StoryImplementedLabel: spec.local.StoryImplementedLabel,
}, nil
}
// Configuration spec ----------------------------------------------------------
type configSpec struct {
global *GlobalConfig
local *LocalConfig
}
func newConfigSpec() *configSpec {
return &configSpec{}
}
func (spec *configSpec) ConfigKey() string {
return ModuleId
}
func (spec *configSpec) ModuleKind() loader.ModuleKind {
return ModuleKind
}
func (spec *configSpec) GlobalConfig() loader.ConfigContainer {
spec.global = &GlobalConfig{}
return spec.global
}
func (spec *configSpec) LocalConfig() loader.ConfigContainer {
spec.local = &LocalConfig{}
return spec.local
}
// Local configuration ---------------------------------------------------------
type LocalConfig struct {
ReviewLabel string `prompt:"with" default:"review" json:"review_issue_label"`
StoryImplementedLabel string `prompt:"as implemented" default:"implemented" json:"story_implemented_label"`
}
// PromptUserForConfig is a part of loader.ConfigContainer interface.
func (local *LocalConfig) PromptUserForConfig() error {
var c LocalConfig
err := prompt.Dialog(&c, "Insert the label to be used to mark the GitHub review issues")
if err != nil {
return err
}
*local = c
return nil
}
// Global configuration --------------------------------------------------------
type GlobalConfig struct {
Token string `prompt:"token to be used for creating GitHub review issues" secret:"true" json:"token"`
}
// PromptUserForConfig is a part of loader.ConfigContainer interface.
func (global *GlobalConfig) PromptUserForConfig() error {
var c GlobalConfig
if err := prompt.Dialog(&c, "Insert the"); err != nil {
return err
}
*global = c
return nil
}