@@ -4,11 +4,12 @@ import (
4
4
"encoding/json"
5
5
"fmt"
6
6
7
+ "github.com/LawnGnome/campaign-schema/override"
8
+ "github.com/LawnGnome/campaign-schema/schema"
7
9
"github.com/gobwas/glob"
8
10
"github.com/hashicorp/go-multierror"
9
11
"github.com/pkg/errors"
10
12
"github.com/sourcegraph/src-cli/internal/campaigns/graphql"
11
- "github.com/sourcegraph/src-cli/schema"
12
13
"github.com/xeipuuv/gojsonschema"
13
14
"gopkg.in/yaml.v2"
14
15
)
@@ -39,20 +40,20 @@ type CampaignSpec struct {
39
40
}
40
41
41
42
type ChangesetTemplate struct {
42
- Title OverridableString `json:"title,omitempty" yaml:"title"`
43
- Body string `json:"body,omitempty" yaml:"body"`
44
- Branch string `json:"branch,omitempty" yaml:"branch"`
43
+ Title override. String `json:"title,omitempty" yaml:"title"`
44
+ Body override. String `json:"body,omitempty" yaml:"body"`
45
+ Branch override. String `json:"branch,omitempty" yaml:"branch"`
45
46
Commit ExpandedGitCommitDescription `json:"commit,omitempty" yaml:"commit"`
46
47
Published OverridableBool `json:"published" yaml:"published"`
47
48
}
48
49
49
50
type GitCommitAuthor struct {
50
- Name string `json:"name" yaml:"name"`
51
- Email string `json:"email" yaml:"email"`
51
+ Name override. String `json:"name" yaml:"name"`
52
+ Email override. String `json:"email" yaml:"email"`
52
53
}
53
54
54
55
type ExpandedGitCommitDescription struct {
55
- Message string `json:"message,omitempty" yaml:"message"`
56
+ Message override. String `json:"message,omitempty" yaml:"message"`
56
57
Author * GitCommitAuthor `json:"author,omitempty" yaml:"author"`
57
58
}
58
59
@@ -150,70 +151,6 @@ func compilePatterns(patterns []string) ([]glob.Glob, error) {
150
151
return globs , nil
151
152
}
152
153
153
- type OverridableString struct {
154
- Default string
155
- Only []* MatchValue
156
- }
157
-
158
- type MatchValue struct {
159
- Match string `json:"match,omitempty" yaml:"match"`
160
- Value string `json:"value,omitempty" yaml:"value"`
161
-
162
- match glob.Glob
163
- }
164
-
165
- func (o * OverridableString ) Value (repo * graphql.Repository ) string {
166
- for _ , mv := range o .Only {
167
- if mv .match .Match (repo .Name ) {
168
- return mv .Value
169
- }
170
- }
171
-
172
- return o .Default
173
- }
174
-
175
- func (o * OverridableString ) MarshalJSON () ([]byte , error ) {
176
- if len (o .Only ) == 0 {
177
- return json .Marshal (o .Default )
178
- }
179
-
180
- return json .Marshal (& struct {
181
- Default string `json:"default,omitempty"`
182
- Only []* MatchValue `json:"only,omitempty"`
183
- }{
184
- Default : o .Default ,
185
- Only : o .Only ,
186
- })
187
- }
188
-
189
- func (o * OverridableString ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
190
- var s string
191
- if err := unmarshal (& s ); err == nil {
192
- o .Default = s
193
- o .Only = []* MatchValue {}
194
- return nil
195
- }
196
-
197
- var temp struct {
198
- Default string `yaml:"default"`
199
- Only []* MatchValue `yaml:"only"`
200
- }
201
- if err := unmarshal (& temp ); err != nil {
202
- return err
203
- }
204
-
205
- o .Default = temp .Default
206
- o .Only = temp .Only
207
- for _ , mv := range o .Only {
208
- var err error
209
- if mv .match , err = glob .Compile (mv .Match ); err != nil {
210
- return errors .Wrapf (err , "compiling repo pattern %q" , mv .match )
211
- }
212
- }
213
-
214
- return nil
215
- }
216
-
217
154
type Step struct {
218
155
Run string `json:"run,omitempty" yaml:"run"`
219
156
Container string `json:"container,omitempty" yaml:"container"`
0 commit comments