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

campaigns: allow partial publishing of changesets #13476

Merged
merged 11 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to Sourcegraph are documented in this file.
- The new GraphQL API query field `namespaceByName(name: String!)` makes it easier to look up the user or organization with the given name. Previously callers needed to try looking up the user and organization separately.
- Changesets created by campaigns will now include a link back to the campaign in their body text. [#14033](https://github.com/sourcegraph/sourcegraph/issues/14033)
- Users can now preview commits that are going to be created in their repositories in the campaign preview UI. [#14181](https://github.com/sourcegraph/sourcegraph/pull/14181)
- A subset of changesets can now be published by setting the `published` flag in campaign specs [to an array](https://docs.sourcegraph.com/@main/user/campaigns/campaign_spec_yaml_reference#publishing-only-specific-changesets), which allows only specific changesets within a campaign to be published based on the repository name. [#13476](https://github.com/sourcegraph/sourcegraph/pull/13476)
- Homepage panels are now enabled by default on Sourcegraph Server. [#14287](https://github.com/sourcegraph/sourcegraph/issues/14287)

### Changed
Expand Down
73 changes: 70 additions & 3 deletions doc/user/campaigns/campaign_spec_yaml_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ changesetTemplate:
branch: campaigns/update-rxjs
commit:
message: Update rxjs to 6.6.2
published: false
published: true
```

```yaml
Expand All @@ -199,7 +199,10 @@ changesetTemplate:
author:
name: Anna Wizard
email: [email protected]
published: true
published:
# Do not meddle in the affairs of wizards, for they are subtle and quick to anger.
- git.istari.example/*: false
- git.istari.example/anna/*: true
```

## [`changesetTemplate.title`](#changesettemplate-title)
Expand Down Expand Up @@ -238,8 +241,72 @@ changesetTemplate:

## [`changesetTemplate.published`](#changesettemplate-published)

Whether to publish the changeset.
Whether to publish the changeset. This may be a boolean value (ie `true` or `false`), or [an array to only publish some changesets within the campaign](#publishing-only-specific-changesets).

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.

### [Publishing only specific changesets](#publishing-only-specific-changesets)

To publish only specific changesets within a campaign, an array of single-element objects can be provided. For example:

```yaml
published:
- github.com/sourcegraph/sourcegraph: true
- github.com/sourcegraph/src-cli: false
```

Each key will be matched against the repository name using [glob](https://godoc.org/github.com/gobwas/glob#Compile) syntax. The [gobwas/glob library](https://godoc.org/github.com/gobwas/glob#Compile) is used for matching, with the key operators being:

| Term | Meaning |
|------|---------|
| `*` | Match any sequence of characters |
| `?` | Match any single character |
| `[ab]` | Match either `a` or `b` |
| `[a-z]` | Match any character between `a` and `z`, inclusive |
| `{abc,def}` | Match either `abc` or `def` |

If multiple entries match a repository, then the last entry will be used. For example, `github.com/a/b` will _not_ be published given this configuration:

```yaml
published:
- github.com/a/*: true
- github.com/*: false
```

If no entries match, then the repository will not be published. To make the default true, add a wildcard entry as the last item in the array:

```yaml
published:
- github.com/*: false
- "*": true
```
Comment on lines +278 to +284
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this just mean "published: true"? Wouldn't the wildcard "*" need to be the first entry to set the default to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


> NOTE: The standalone `"*"` is quoted in the key to avoid ambiguity in the YAML document.

### Examples

To publish all changesets created by a campaign:

```yaml
changesetTemplate:
published: true
```

To only publish changesets within the `sourcegraph` GitHub organization:

```yaml
changesetTemplate:
published:
- github.com/sourcegraph/*: true
```

To publish all changesets that are not on GitLab:

```yaml
changesetTemplate:
published:
- gitlab.com/*: false
- "*": true
```
2 changes: 1 addition & 1 deletion doc/user/campaigns/hello_world_campaign.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Publishing causes commits, branches, and changesets to be created on your code h

You probably don't want to publish these toy "Hello World" changesets to actively developed repositories, because that might confuse people ("Why did you add this line to our READMEs?").

On a real campaign, you would change the `published: false` in the `hello-world.campaign.yaml` to `published: true` and run the `src campaign preview` command again. The changesets will then be published when you create or update the campaign from the preview.
On a real campaign, you would change the `published: false` in the `hello-world.campaign.yaml` to `published: true` and run the `src campaign preview` command again. The changesets will then be published when you create or update the campaign from the preview. You can also [publish only some of the changesets by setting `published` to an array](campaign_spec_yaml_reference.md#publishing-only-specific-changesets).

> NOTE: You can also create or update a campaign by running `src campaign apply`! This skips the preview stage, and is especially useful when updating an existing campaign.

Expand Down
4 changes: 3 additions & 1 deletion doc/user/campaigns/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ name: hello-world

changesetTemplate:
# ...
published: false
published: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What. the. hell. How did I manage to get that wrong? 😄

```

> NOTE: You can also [publish some of a campaign's changesets](campaign_spec_yaml_reference.md#publishing-only-specific-changesets).

Then run the `src campaign preview` command again, or `src campaign apply` to immediately publish the changesets.

In the Sourcegraph web UI you'll see a progress indicator for the changesets that are being published. Any errors will be shown, and you can retry publishing after you've resolved the problem by running `src campaign apply` again. You don't need to worry about multiple branches or pull requests being created when you retry, because the same branch name will be used.
Expand Down
3 changes: 2 additions & 1 deletion enterprise/internal/campaigns/resolvers/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/graph-gophers/graphql-go"
"github.com/sourcegraph/campaignutils/overridable"
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
"github.com/sourcegraph/sourcegraph/cmd/repo-updater/repos"
Expand Down Expand Up @@ -296,7 +297,7 @@ func TestApplyCampaign(t *testing.T) {
Commit: campaigns.CommitTemplate{
Message: "Add hello world",
},
Published: false,
Published: overridable.FromBool(false),
},
},
UserID: userID,
Expand Down
3 changes: 2 additions & 1 deletion enterprise/internal/campaigns/store_campaign_specs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"github.com/sourcegraph/campaignutils/overridable"
"github.com/sourcegraph/sourcegraph/cmd/repo-updater/repos"
"github.com/sourcegraph/sourcegraph/internal/campaigns"
cmpgn "github.com/sourcegraph/sourcegraph/internal/campaigns"
Expand All @@ -28,7 +29,7 @@ func testStoreCampaignSpecs(t *testing.T, ctx context.Context, s *Store, _ repos
Commit: campaigns.CommitTemplate{
Message: "commit message",
},
Published: false,
Published: overridable.FromBool(false),
},
},
UserID: int32(i + 1234),
Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ go 1.14
require (
cloud.google.com/go/bigquery v1.6.0 // indirect
cloud.google.com/go/pubsub v1.3.1
github.com/Depado/bfchroma v1.3.0 // indirect
github.com/Masterminds/semver v1.5.0
github.com/NYTimes/gziphandler v1.1.1
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/RoaringBitmap/roaring v0.5.1
github.com/alecthomas/chroma v0.8.1 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/aphistic/sweet-junit v0.2.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
Expand All @@ -30,7 +28,6 @@ require (
github.com/dgraph-io/ristretto v0.0.3
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dineshappavoo/basex v0.0.0-20170425072625-481a6f6dc663
github.com/dlclark/regexp2 v1.2.1 // indirect
github.com/dnaeon/go-vcr v1.0.1
github.com/efritz/glock v0.0.0-20181228234553-f184d69dff2c
github.com/efritz/go-genlib v0.0.0-20200616012750-c21aae2e13ac // indirect
Expand Down Expand Up @@ -152,16 +149,15 @@ require (
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
github.com/sourcegraph/campaignutils v0.0.0-20200930165749-a8777d33a817
github.com/sourcegraph/codeintelutils v0.0.0-20200824140252-1db3aed5cf58
github.com/sourcegraph/ctxvfs v0.0.0-20180418081416-2b65f1b1ea81
github.com/sourcegraph/docsite v1.5.1-0.20201001050606-ec11d65e366a // indirect
github.com/sourcegraph/go-ctags v0.0.0-20200922223002-071e508aa451
github.com/sourcegraph/go-diff v0.6.1
github.com/sourcegraph/go-jsonschema v0.0.0-20200907102109-d14e9f2f3a28
github.com/sourcegraph/go-langserver v2.0.1-0.20181108233942-4a51fa2e1238+incompatible
github.com/sourcegraph/go-lsp v0.0.0-20200429204803-219e11d77f5d
github.com/sourcegraph/gosyntect v0.0.0-20200429204402-842ed26129d0
github.com/sourcegraph/jsonschemadoc v0.0.0-20200429204751-398086c46c99 // indirect
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
Expand Down
Loading