Skip to content

Commit 6fe57ad

Browse files
authored
campaigns: allow partial publishing of changesets (#294)
1 parent 82c11c8 commit 6fe57ad

File tree

7 files changed

+46
-6
lines changed

7 files changed

+46
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ All notable changes to `src-cli` are documented in this file.
1313

1414
### Added
1515

16+
- The `published` flag in campaign specs may now be an array, which allows only specific changesets within a campaign to be published based on the repository name. [#294](https://github.com/sourcegraph/src-cli/pull/294)
17+
1618
### Changed
1719

1820
- Error reporting by `src campaign [preview|apply]` has been improved and now includes more information about which step failed in which repository. [#325](https://github.com/sourcegraph/src-cli/pull/325)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/olekukonko/tablewriter v0.0.4 // indirect
1717
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
1818
github.com/pkg/errors v0.9.1
19+
github.com/sourcegraph/campaignutils v0.0.0-20200930165749-a8777d33a817
1920
github.com/sourcegraph/codeintelutils v0.0.0-20200824140252-1db3aed5cf58
2021
github.com/sourcegraph/go-diff v0.6.0
2122
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4
44
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
55
github.com/efritz/pentimento v0.0.0-20190429011147-ade47d831101 h1:RylpU+KNJJNEJIk3o8gZ70uPTlutxaYnikKNPko39LA=
66
github.com/efritz/pentimento v0.0.0-20190429011147-ade47d831101/go.mod h1:5ALWO82UZwfAtNRUtwzsWimcrcuYzyieTyyXOXrP6EQ=
7+
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
8+
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
79
github.com/google/go-cmp v0.4.1 h1:/exdXoGamhu5ONeUJH0deniYLWYvQwW66yvlfiiKTu0=
810
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
911
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
@@ -35,6 +37,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
3537
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3638
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
3739
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
40+
github.com/sourcegraph/campaignutils v0.0.0-20200930165749-a8777d33a817 h1:mdFA7I2rnfl8AV0m8iMb4uoQb3GRdjRsgRMREoNGEk4=
41+
github.com/sourcegraph/campaignutils v0.0.0-20200930165749-a8777d33a817/go.mod h1:5P8k8KlKz78RZJ2EFk9k9ln/j/twj28z/+BvO5hHZJ8=
3842
github.com/sourcegraph/codeintelutils v0.0.0-20200824140252-1db3aed5cf58 h1:Ps+U1xoZP+Zoph39YfRB6Q846ghO8pgrAgp0MiObvPs=
3943
github.com/sourcegraph/codeintelutils v0.0.0-20200824140252-1db3aed5cf58/go.mod h1:HplI8gRslTrTUUsSYwu28hSOderix7m5dHNca7xBzeo=
4044
github.com/sourcegraph/go-diff v0.6.0 h1:WbN9e/jD8ujU+o0vd9IFN5AEwtfB0rn/zM/AANaClqQ=

internal/campaigns/campaign_spec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/hashicorp/go-multierror"
77
"github.com/pkg/errors"
8+
"github.com/sourcegraph/campaignutils/overridable"
89
"github.com/sourcegraph/src-cli/schema"
910
"github.com/xeipuuv/gojsonschema"
1011
"gopkg.in/yaml.v2"
@@ -40,7 +41,7 @@ type ChangesetTemplate struct {
4041
Body string `json:"body,omitempty" yaml:"body"`
4142
Branch string `json:"branch,omitempty" yaml:"branch"`
4243
Commit ExpandedGitCommitDescription `json:"commit,omitempty" yaml:"commit"`
43-
Published bool `json:"published" yaml:"published"`
44+
Published overridable.Bool `json:"published" yaml:"published"`
4445
}
4546

4647
type GitCommitAuthor struct {

internal/campaigns/executor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ func reachedTimeout(cmdCtx context.Context, err error) bool {
294294
}
295295

296296
func createChangesetSpec(task *Task, diff string) *ChangesetSpec {
297+
repo := task.Repository.Name
298+
297299
var authorName string
298300
var authorEmail string
299301

@@ -323,7 +325,7 @@ func createChangesetSpec(task *Task, diff string) *ChangesetSpec {
323325
Diff: string(diff),
324326
},
325327
},
326-
Published: task.Template.Published,
328+
Published: task.Template.Published.Value(repo),
327329
},
328330
}
329331
}

schema/campaign_spec.schema.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,24 @@
153153
}
154154
},
155155
"published": {
156-
"type": "boolean",
157156
"description": "Whether to publish the changeset. An unpublished changeset can be previewed on Sourcegraph by any person who can view the campaign, but its commit, branch, and pull request aren't created on the code host. A published changeset results in a commit, branch, and pull request being created on the code host.",
158-
"$comment": "TODO(sqs): Come up with a way to specify that only a subset of changesets should be published. For example, making `published` an array with some include/exclude syntax items."
157+
"oneOf": [
158+
{
159+
"type": "boolean",
160+
"description": "A single flag to control the publishing state for the entire campaign."
161+
},
162+
{
163+
"type": "array",
164+
"description": "A list of glob patterns to match repository names. In the event multiple patterns match, the last matching pattern in the list will be used.",
165+
"items": {
166+
"type": "object",
167+
"description": "An object with one field: the key is the glob pattern to match against repository names; the value will be used as the published flag for matching repositories.",
168+
"additionalProperties": { "type": "boolean" },
169+
"minProperties": 1,
170+
"maxProperties": 1
171+
}
172+
}
173+
]
159174
}
160175
}
161176
}

schema/campaign_spec_stringdata.go

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)