Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 2769aa5

Browse files
committed
_Very_ rough implementation of the new schema.
1 parent d67e57e commit 2769aa5

File tree

6 files changed

+479
-61
lines changed

6 files changed

+479
-61
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
cloud.google.com/go/bigquery v1.6.0 // indirect
77
cloud.google.com/go/pubsub v1.3.1
88
github.com/DataDog/zstd v1.4.5 // indirect
9+
github.com/LawnGnome/campaign-schema v0.0.0-20200915044008-fb956c216a65
910
github.com/Masterminds/semver v1.5.0
1011
github.com/NYTimes/gziphandler v1.1.1
1112
github.com/OneOfOne/xxhash v1.2.8 // indirect
@@ -55,7 +56,7 @@ require (
5556
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
5657
github.com/gomodule/oauth1 v0.0.0-20181215000758-9a59ed3b0a84
5758
github.com/gomodule/redigo v2.0.0+incompatible
58-
github.com/google/go-cmp v0.5.0
59+
github.com/google/go-cmp v0.5.2
5960
github.com/google/go-github v17.0.0+incompatible
6061
github.com/google/go-github/v28 v28.1.1
6162
github.com/google/go-github/v31 v31.0.0

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ github.com/DataDog/zstd v1.4.4/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t
5858
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
5959
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
6060
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
61+
github.com/LawnGnome/campaign-schema v0.0.0-20200915044008-fb956c216a65 h1:3Hzx2CeDsf/hoAr3zEhRbG2IUnb3FaBojsTJMkWsz90=
62+
github.com/LawnGnome/campaign-schema v0.0.0-20200915044008-fb956c216a65/go.mod h1:PSeUirk5RYbWn64QnwEL0e4eo7fCiwQ3zqNV3PtGifE=
6163
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
6264
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
6365
github.com/Microsoft/go-winio v0.4.11 h1:zoIOcVf0xPN1tnMVbTtEdI+P8OofVk3NObnwOQ6nK2Q=
@@ -584,8 +586,8 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
584586
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
585587
github.com/google/go-cmp v0.4.1 h1:/exdXoGamhu5ONeUJH0deniYLWYvQwW66yvlfiiKTu0=
586588
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
587-
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
588-
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
589+
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
590+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
589591
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
590592
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
591593
github.com/google/go-github/v27 v27.0.6 h1:oiOZuBmGHvrGM1X9uNUAUlLgp5r1UUO/M/KnbHnLRlQ=
@@ -1199,10 +1201,6 @@ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG
11991201
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
12001202
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 h1:z/MpntplPaW6QW95pzcAR/72Z5TWDyDnSo0EOcyij9o=
12011203
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
1202-
github.com/sourcegraph/zoekt v0.0.0-20200908080019-f95cecffc54f h1:Utx9Yq9NlgWURzjFVdEl9dtutgiM2uyevi+VPnsZI0w=
1203-
github.com/sourcegraph/zoekt v0.0.0-20200908080019-f95cecffc54f/go.mod h1:Cj/TaflDEk8QLJnV9mJP5hVswI9bEePpod/d9iLR4Kk=
1204-
github.com/sourcegraph/zoekt v0.0.0-20200911123057-422d5b68c06e h1:arEEamCq+/vT8iayW5jDeR6RRu2r0MNj9bhrY15YvAU=
1205-
github.com/sourcegraph/zoekt v0.0.0-20200911123057-422d5b68c06e/go.mod h1:Cj/TaflDEk8QLJnV9mJP5hVswI9bEePpod/d9iLR4Kk=
12061204
github.com/sourcegraph/zoekt v0.0.0-20200911142020-36f86e63516f h1:JgRyqVKhF2UQB/YrLHkk9B4gjrBTjz3Pq0PQrfJ4XD4=
12071205
github.com/sourcegraph/zoekt v0.0.0-20200911142020-36f86e63516f/go.mod h1:Cj/TaflDEk8QLJnV9mJP5hVswI9bEePpod/d9iLR4Kk=
12081206
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=

internal/campaigns/types.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/LawnGnome/campaign-schema/override"
13+
cschema "github.com/LawnGnome/campaign-schema/schema"
1214
"github.com/ghodss/yaml"
1315
"github.com/graph-gophers/graphql-go"
1416
"github.com/hashicorp/go-multierror"
@@ -1714,7 +1716,7 @@ func (cs *CampaignSpec) Clone() *CampaignSpec {
17141716
// UnmarshalValidate unmarshals the RawSpec into Spec and validates it against
17151717
// the CampaignSpec schema and does additional semantic validation.
17161718
func (cs *CampaignSpec) UnmarshalValidate() error {
1717-
return unmarshalValidate(schema.CampaignSpecSchemaJSON, []byte(cs.RawSpec), &cs.Spec)
1719+
return unmarshalValidate(cschema.CampaignSpecJSON, []byte(cs.RawSpec), &cs.Spec)
17181720
}
17191721

17201722
// CampaignSpecTTL specifies the TTL of CampaignSpecs that haven't been applied
@@ -1728,11 +1730,12 @@ func (cs *CampaignSpec) ExpiresAt() time.Time {
17281730
}
17291731

17301732
type CampaignSpecFields struct {
1731-
Name string `json:"name"`
1732-
Description string `json:"description"`
1733-
On []CampaignSpecOn `json:"on"`
1734-
Steps []CampaignSpecStep `json:"steps"`
1735-
ChangesetTemplate ChangesetTemplate `json:"changesetTemplate"`
1733+
Name string `json:"name"`
1734+
Description string `json:"description"`
1735+
On []CampaignSpecOn `json:"on"`
1736+
Steps []CampaignSpecStep `json:"steps"`
1737+
ImportChangeset []CampaignImportChangeset `json:"importChangesets"`
1738+
ChangesetTemplate *ChangesetTemplate `json:"changesetTemplate"`
17361739
}
17371740

17381741
type CampaignSpecOn struct {
@@ -1746,18 +1749,23 @@ type CampaignSpecStep struct {
17461749
Env map[string]string `json:"env"`
17471750
}
17481751

1752+
type CampaignImportChangeset struct {
1753+
Repository string `json:"repository"`
1754+
ExternalIDs []interface{} `json:"externalIDs"`
1755+
}
1756+
17491757
// FIXME: the Title and Published fields should be unmarshalled properly to
17501758
// handle the new oneOf types in the campaign spec schema.
17511759
type ChangesetTemplate struct {
1752-
Title interface{} `json:"title"`
1753-
Body string `json:"body"`
1754-
Branch string `json:"branch"`
1755-
Commit CommitTemplate `json:"commit"`
1756-
Published interface{} `json:"published"`
1760+
Title override.String `json:"title"`
1761+
Body override.String `json:"body"`
1762+
Branch override.String `json:"branch"`
1763+
Commit CommitTemplate `json:"commit"`
1764+
Published interface{} `json:"published"`
17571765
}
17581766

17591767
type CommitTemplate struct {
1760-
Message string `json:"message"`
1768+
Message override.String `json:"message"`
17611769
}
17621770

17631771
func NewChangesetSpecFromRaw(rawSpec string) (*ChangesetSpec, error) {

schema/campaign_spec.schema.json

Lines changed: 192 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,18 @@
124124
},
125125
{
126126
"type": "object",
127-
"required": ["default", "only"],
127+
"required": ["default"],
128128
"additionalProperties": false,
129129
"properties": {
130130
"default": {
131131
"type": "string",
132-
"description": "The title to use for all changesets that do not match any of the rules in the only array."
132+
"description": "The title to use for all changesets that do not match any of the rules in the except array."
133133
},
134-
"only": {
134+
"except": {
135135
"type": "array",
136136
"items": {
137137
"type": "object",
138+
"title": "TitleExcept",
138139
"required": ["match", "value"],
139140
"additionalProperties": false,
140141
"properties": {
@@ -154,12 +155,82 @@
154155
]
155156
},
156157
"body": {
157-
"type": "string",
158-
"description": "The body (description) of the changeset."
158+
"description": "The body (description) of the changeset.",
159+
"oneOf": [
160+
{
161+
"type": "string",
162+
"description": "The body to use for the entire campaign."
163+
},
164+
{
165+
"type": "object",
166+
"required": ["default"],
167+
"additionalProperties": false,
168+
"properties": {
169+
"default": {
170+
"type": "string",
171+
"description": "The body to use for all changesets that do not match any of the rules in the except array."
172+
},
173+
"except": {
174+
"type": "array",
175+
"items": {
176+
"type": "object",
177+
"title": "BodyExcept",
178+
"required": ["match", "value"],
179+
"additionalProperties": false,
180+
"properties": {
181+
"match": {
182+
"type": "string",
183+
"description": "The repository name to match. Glob wildcards are supported."
184+
},
185+
"value": {
186+
"type": "string",
187+
"description": "The body to use for changesets that match this rule."
188+
}
189+
}
190+
}
191+
}
192+
}
193+
}
194+
]
159195
},
160196
"branch": {
161-
"type": "string",
162-
"description": "The name of the Git branch to create or update on each repository with the changes."
197+
"description": "The name of the Git branch to create or update on each repository with the changes.",
198+
"oneOf": [
199+
{
200+
"type": "string",
201+
"description": "The branch name to use for the entire campaign."
202+
},
203+
{
204+
"type": "object",
205+
"required": ["default"],
206+
"additionalProperties": false,
207+
"properties": {
208+
"default": {
209+
"type": "string",
210+
"description": "The branch name to use for all changesets that do not match any of the rules in the except array."
211+
},
212+
"except": {
213+
"type": "array",
214+
"items": {
215+
"type": "object",
216+
"title": "BranchExcept",
217+
"required": ["match", "value"],
218+
"additionalProperties": false,
219+
"properties": {
220+
"match": {
221+
"type": "string",
222+
"description": "The repository name to match. Glob wildcards are supported."
223+
},
224+
"value": {
225+
"type": "string",
226+
"description": "The branch name to use for changesets that match this rule."
227+
}
228+
}
229+
}
230+
}
231+
}
232+
}
233+
]
163234
},
164235
"commit": {
165236
"title": "ExpandedGitCommitDescription",
@@ -169,8 +240,43 @@
169240
"required": ["message"],
170241
"properties": {
171242
"message": {
172-
"type": "string",
173-
"description": "The Git commit message."
243+
"description": "The Git commit message.",
244+
"oneOf": [
245+
{
246+
"type": "string",
247+
"description": "The commit message to use for the entire campaign."
248+
},
249+
{
250+
"type": "object",
251+
"required": ["default"],
252+
"additionalProperties": false,
253+
"properties": {
254+
"default": {
255+
"type": "string",
256+
"description": "The commit message to use for all changesets that do not match any of the rules in the except array."
257+
},
258+
"except": {
259+
"type": "array",
260+
"items": {
261+
"type": "object",
262+
"title": "GitCommitMessageExcept",
263+
"required": ["match", "value"],
264+
"additionalProperties": false,
265+
"properties": {
266+
"match": {
267+
"type": "string",
268+
"description": "The repository name to match. Glob wildcards are supported."
269+
},
270+
"value": {
271+
"type": "string",
272+
"description": "The commit message to use for changesets that match this rule."
273+
}
274+
}
275+
}
276+
}
277+
}
278+
}
279+
]
174280
},
175281
"author": {
176282
"title": "GitCommitAuthor",
@@ -180,13 +286,85 @@
180286
"required": ["name", "email"],
181287
"properties": {
182288
"name": {
183-
"type": "string",
184-
"description": "The Git commit author name."
289+
"description": "The Git commit author name.",
290+
"oneOf": [
291+
{
292+
"type": "string",
293+
"description": "The author name to use for the entire campaign."
294+
},
295+
{
296+
"type": "object",
297+
"required": ["default"],
298+
"additionalProperties": false,
299+
"properties": {
300+
"default": {
301+
"type": "string",
302+
"description": "The author name to use for all changesets that do not match any of the rules in the except array."
303+
},
304+
"except": {
305+
"type": "array",
306+
"items": {
307+
"type": "object",
308+
"title": "GitCommitAuthorExcept",
309+
"required": ["match", "value"],
310+
"additionalProperties": false,
311+
"properties": {
312+
"match": {
313+
"type": "string",
314+
"description": "The repository name to match. Glob wildcards are supported."
315+
},
316+
"value": {
317+
"type": "string",
318+
"description": "The author name to use for changesets that match this rule."
319+
}
320+
}
321+
}
322+
}
323+
}
324+
}
325+
]
185326
},
186327
"email": {
187-
"type": "string",
188-
"format": "email",
189-
"description": "The Git commit author email."
328+
"description": "The Git commit author email.",
329+
"oneOf": [
330+
{
331+
"type": "string",
332+
"format": "email",
333+
"description": "The author email to use for the entire campaign."
334+
},
335+
{
336+
"type": "object",
337+
"required": ["default"],
338+
"additionalProperties": false,
339+
"properties": {
340+
"default": {
341+
"type": "string",
342+
"format": "email",
343+
"description": "The author email to use for all changesets that do not match any of the rules in the except array."
344+
},
345+
"except": {
346+
"type": "array",
347+
"items": {
348+
"type": "object",
349+
"title": "GitCommitEmailExcept",
350+
"required": ["match", "value"],
351+
"additionalProperties": false,
352+
"properties": {
353+
"match": {
354+
"type": "string",
355+
"description": "The repository name to match. Glob wildcards are supported."
356+
},
357+
"value": {
358+
"type": "string",
359+
"format": "email",
360+
"description": "The author email to use for changesets that match this rule."
361+
}
362+
}
363+
}
364+
}
365+
}
366+
}
367+
]
190368
}
191369
}
192370
}

0 commit comments

Comments
 (0)