diff --git a/doc/_resources/templates/document.html b/doc/_resources/templates/document.html index 2b1e3f6cebd8..f8bd6fcafcb0 100644 --- a/doc/_resources/templates/document.html +++ b/doc/_resources/templates/document.html @@ -116,27 +116,7 @@
+ | Kubernetes Deployment | +Sourcegraph campaign | +
---|---|---|
What underlying thing does this API manage? | +Pods running on many (possibly unreliable) nodes | +Branches and changesets on many repositories that can be rate-limited and externally modified (and our authorization can change) | +
Spec YAML | +
+
+ |
+
+
|
+
How desired state is computed | +
+
|
+
+
|
+
Desired state consists of... | +
+
|
+
+
|
+
Where is the desired state computed? | +The deployment controller (part of the Kubernetes cluster) consults the DeploymentSpec and continuously computes the desired state. | +
+ The Sourcegraph CLI (running on your local machine, not on the Sourcegraph server) consults the campaign spec and computes the desired state when you invoke Difference vs. Kubernetes: A campaign's desired state is computed locally, not on the server. It requires executing arbitrary commands, which is not yet supported by the Sourcegraph server. See campaigns known issue "Campaign steps are run locally...". + |
+
Reconciling desired state vs. actual state | +The "deployment controller" reconciles the resulting PodSpecs against the current actual PodSpecs (and does smart things like rolling deploy). | +The "campaign controller" (i.e., our backend) reconciles the resulting ChangesetSpecs against the current actual changesets (and does smart things like gradual roll-out/publishing and auto-merging when checks pass). | +
src campaign apply -f hello-world.campaign.yaml -preview
+1. Wait for it to run and compute the changes for each repository.
+1. When it's done, click the displayed link to see all of the changes that will be made.
+1. Make sure the changes look right.
+
+ > If you want to run the campaign on fewer repositories, change the roots query in `hello-world.campaign.yaml` to something like `file:README.md repo:myproject` (to only match repositories whose name contains `myproject`).
+1. Click the **Create campaign** button.
+
+You created your first campaign! The campaign's changesets are still unpublished, which means they exist only on Sourcegraph and haven't been pushed to your code host yet.
+
+## Step 3. Publish the changes (optional)
+
+Publishing causes commits, branches, and changesets to be created on your code host.
+
+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 click the **Publish** button next to a changeset to publish it (or the **Publish all** button to publish all changesets).
+
+## Congratulations!
+
+You've created your first campaign! 🎉🎉
+
+You can customize your campaign spec and experiment with making other types of changes. To update your campaign, edit `hello-world.campaign.yaml` and run `src campaign apply -f hello-world.campaign.yaml -preview` again. (As before, you'll see a preview before any changes are applied.)
+
+Here are some [example campaigns](examples/index.md) for inspiratiopn:
+
+- [Using ESLint to automatically migrate to a new TypeScript version](examples/eslint_typescript_version.md)
+- [Adding a GitHub action to upload LSIF data to Sourcegraph](examples/lsif_action.md)
+- [Refactoring Go code using Comby](examples/refactor_go_comby.md)
+
+To learn what else you can do with campaigns, see "[Campaigns](index.md)" in Sourcegraph documentation.
diff --git a/doc/user/campaigns/index.md b/doc/user/campaigns/index.md
index 0abbc9e3294c..18b734eb6f6f 100644
--- a/doc/user/campaigns/index.md
+++ b/doc/user/campaigns/index.md
@@ -1,90 +1,253 @@
# Campaigns
->NOTE: **Campaigns are currently in beta.** We're actively building out the feature set and improving the user experience with every update. Let us know what you think! [File an issue](https://github.com/sourcegraph/sourcegraph) with feedback/problems/questions, or [contact us directly](https://about.sourcegraph.com/contact).
+Campaigns let you make large-scale code changes across many repositories.
-## What are campaigns?
+> NOTE: Campaigns are in beta.
-Campaigns are part of [Sourcegraph code change management](https://about.sourcegraph.com/product/code-change-management) and let you make large-scale code changes across many repositories and different code hosts.
+## About campaigns
-You provide the code to make the change, and campaigns provide the plumbing to turn it into a large-scale code change campaign and monitor its progress.
+A campaign streamlines the creation and tracking of pull requests across many repositories and code hosts. After you create a campaign, you tell it what changes to make (by providing a list of repositories and a script to run in each). The campaign lets you create pull requests on all affected repositories, and it tracks their progress until they're all merged. You can preview the changes and update them at any time.
-src campaign apply -f YOUR_CAMPAIGN_SPEC.campaign.yaml -preview
+
+ > **Don't worry!** Before any branches are pushed or changesets (e.g., GitHub pull requests) are created, you will see a preview of all changes and can confirm each one before proceeding.
+1. Wait for it to run and compute the changes for each repository (using the repositories and commands in the campaign spec).
+1. Open the preview URL that the command printed out.
+1. Examine the preview. Confirm that the changes are what you intended. (If not, edit the campaign spec and then rerun the command above.)
+1. Click the **Create campaign** button.
+
+After you've applied a campaign spec, you can [publish changesets](#publishing-changesets-to-the-code-host) to the code host when you're ready. This will turn the patches into commits, branches, and changesets (such as GitHub pull requests) for others to review and merge.
+
+You can share the link to your campaign with other people if you want their help. Any person on your Sourcegraph instance can [view it in the campaigns list](#viewing-campaigns).
+
+If a person viewing the campaign lacks read access to a repository in the campaign, they can only see [limited information about the changes to that repository](managing_access.md#repository-permissions-for-campaigns) (and not the repository name, file paths, or diff).
+
+You can update a campaign's changes at any time, even after you've published changesets. For more information, see "[Updating a campaign](#updating-a-campaign)".
+
+### Example campaigns
+
+The [example campaigns](examples/index.md) show how to use campaigns to make useful, real-world changes:
+
+- [Using ESLint to automatically migrate to a new TypeScript version](examples/eslint_typescript_version.md)
+- [Adding a GitHub action to upload LSIF data to Sourcegraph](examples/lsif_action.md)
+- [Refactoring Go code using Comby](examples/refactor_go_comby.md)
+
+## Publishing changesets to the code host
+
+After you've added patches, you can see a preview of the changesets (e.g., GitHub pull requests) that will be created from the patches. Publishing the changesets will, for each repository:
+
+- Create a commit with the changes (from the patches for that repository)
+- Push a branch (using the branch name you chose when creating the campaign)
+- Create a changeset (e.g., GitHub pull request) on the code host for review and merging
+
+When you're ready, you can publish some or all of a campaign's changesets.
+
+> TODO(sqs): add steps for updating campaign spec's `changesetTemplate` to publish
+
+You'll see a progress indicator when changesets are being published. Any errors will be shown, and you can retry publishing after you've resolved the problem. You don't need to worry about it creating multiple branches or pull requests when you retry, because it uses the same branch name.
+
+To publish a changeset, you need admin access to the campaign and write access to the changeset's repository (on the code host). For more information, see "[Code host interactions in campaigns](managing_access.md#code-host-interactions-in-campaigns)". [Forking the repository](#known-issues) is not yet supported.
+
+## Tracking campaign progress and changeset statuses
+
+A campaign tracks all of its changesets for updates to:
+
+- Status: open, merged, or closed
+- Checks: passed (green), failed (red), or pending (yellow)
+- Review status: approved, changes requested, pending, or other statuses (depending on your code host or code review tool)
+
+You can see the overall trend of a campaign in the burndown chart, which shows the proportion of changesets that have been merged over time since the campaign was created.
+
+> TODO(sqs) screenshot
+
+In the list of changesets, you can see the detailed status for each changeset.
+
+> TODO(sqs) screenshot
+
+If you lack read access to a repository, you can only see [limited information about the changes to that repository](managing_access.md#repository-permissions-for-campaigns) (and not the repository name, file paths, or diff).
+
+## Updating a campaign
+
+
+
+You can edit a campaign's name, description, and any other part of its campaign spec at any time.
+
+To update a campaign, you need [admin access to the campaign](managing_access.md#campaign-access-for-each-permission-level), and [write access to all affected repositories](managing_access.md#repository-permissions-for-campaigns) with published changesets.
+
+1. In your terminal, run the [Sourcegraph CLI (`src`)](https://github.com/sourcegraph/src-cli) command shown. The command will execute your campaign spec to generate changes and then upload them to the campaign for you to preview and accept.
+
+ src campaign apply -f YOUR_CAMPAIGN_SPEC.campaign.yaml -preview
+
+ > **Don't worry!** Before any branches or changesets are modified, you will see a preview of all changes and can confirm before proceeding.
+1. Open the preview URL that the command printed out.
+1. Examine the preview. Confirm that the changes are what you intended. (If not, edit your campaign spec and then rerun the command above.)
+1. Click the **Update campaign** button.
+
+All of the changesets on your code host will be updated to the desired state that was shown in the preview.
+
+## Tracking existing changesets
+
+
+
+1. Click the campaigns icon in the top navigation bar.
+1. *To use an existing campaign:* In the list of campaigns, click the campaign where you'd like to track existing changesets.
+
+ *To create a new campaign:* Click the **+ New campaign** button. For more information, see "[Creating a new campaign](#creating-a-new-campaign)".
+1. Click the **Track existing changeset** button in the top right of the **Changesets** list.
+1. Type in the name of the changeset's repository.
+
+ This is the repository's name on Sourcegraph. If you can visit the repository at `https://sourcegraph.example.com/foo/bar`, the name is `foo/bar`. Depending on the configuration, it may or may not begin with a hostname (such as `github.com/foo/bar`).
+1. Type in the changeset number (e.g., the GitHub pull request number).
+1. Click **Add**.
+
+You'll see the existing changeset in the list. The campaign will track the changeset's status and include it in the overall campaign progress (in the same way as if it had been created by the campaign). For more information, see "[Tracking campaign progress and changeset statuses](#tracking-campaign-progress-and-changeset-statuses)".
+
+## Closing or deleting a campaign
+
+You can close a campaign when you don't need it anymore, when all changes have been merged, or when you decided not to proceed with making all of the changes. A closed campaign still appears in the [campaigns list](#viewing-campaigns). To completely remove it, you can delete the campaign.
+
+Any person with [admin access to the campaign](managing_access.md#permission-levels-for-campaigns) can close or delete it.
+
+1. Click the campaigns icon in the top navigation bar.
+1. In the list of campaigns, click the campaign that you'd like to close or delete.
+1. In the top right, click the **Close**.
+1. Select whether you want to close all of the campaign's changesets (e.g., closing all associated GitHub pull requests on the code host).
+1. Click **TODO(sqs)** .
+
+## [Managing access to campaigns](managing_access.md)
+
+See "[Managing access to campaigns](managing_access.md)".
+
+## Code host and repository permissions in campaigns
+
+All actions on the code host (such as pushing a branch or opening a changeset) are performed by your individual user account, not by a bot user. For more information, see "[Code host interactions in campaigns](managing_access.md#code-host-interactions-in-campaigns)".
+
+[Repository permissions](../../admin/repo/permissions.md) are enforced when campaigns display information. For more information, see "[Repository permissions in campaigns](managing_access.md#repository-permissions-for-campaigns)".
+
+## Site admin configuration for campaigns
+
+Using campaigns requires a [code host connection](../../admin/external_service/index.md) to a supported code host (currently GitHub and Bitbucket Server).
+
+Site admins can also:
+
+- [Allow users to authenticate via the code host](../../admin/auth/index.md#github), which makes it easier for users to authorize [code host interactions in campaigns](managing_access.md#code-host-interactions-in-campaigns)
+- [Configure repository permissions](../../admin/repo/permissions.md), which campaigns will respect
+- [Disable campaigns for all users](managing_access.md#disabling-campaigns-for-all-users)
+
+## Concepts
+
+- A **campaign** is group of related changes to code, along with a title and description.
+- The campaign has associated **changesets**, which is a generic term for pull requests, merge requests, or any other reviewable chunk of code. (Code hosts use different terms for this, which is why we chose a generic term.)
+- A **published changeset** means the commit, branch, and changeset have been created on the code host. An **unpublished changeset** is just a preview that you can view in the campaign but does not exist on the code host yet.
+- A **spec** (campaign spec or changeset spec) is a "record of intent". When you provide a spec for a thing, the system will continuously try to reconcile the actual thing with your desired intent (as described by the spec). This involves creating, updating, and deleting things as needed.
+- {#campaign-spec} A **campaign spec** is a YAML file describing the campaign: repositories to change, commands to run, and a template for changesets and commits. You describe your high-level intent in the campaign spec, such as "lint files in all repositories with a `package.json` file".
+- A campaign has many **changeset specs**, which are produced by executing the campaign spec (i.e., running the commands on each selected repository) and then using its changeset template to produce a list of changesets, including the diffs, commit messages, changeset title, and changeset body. You don't need to view or edit the raw changeset specs; you will edit the campaign spec and view the changesets in the UI.
+- The **campaign controller** reconciles the actual state of the campaign's changesets on the code host so that they match your desired intent (as described in the changeset specs).
+
+To learn about the internals of campaigns, see "[Campaigns](../../dev/campaigns_development.md)" in the developer documentation.
+
+## Roadmap
+
+
+
+### Known issues
+
+
+
+- The only supported code hosts are GitHub and Bitbucket Server. Support for [all other code hosts](../../admin/external_service/index.md) is planned.
+- It is not yet possible for a campaign to have multiple changesets in a single repository (e.g., to make changes to multiple subtrees in a monorepo).
+- Forking a repository and creating a pull request on the fork is not yet supported. Because of this limitation, you need write access to each repository that your campaign will change (in order to push a branch to it).
+- Campaign steps are run locally (in the [Sourcegraph CLI](https://github.com/sourcegraph/src-cli)). Sourcegraph does not yet support executing campaign steps (which can be arbitrary commands) on the server. For this reason, the APIs for creating and updating a campaign require you to upload all of the changeset specs (which are produced by executing the campaign spec locally). {#server-execution}
-Campaigns currently only support **GitHub** and **Bitbucket Server** repositories. If you're interested in using campaigns on other code hosts, [let us know](https://about.sourcegraph.com/contact).
diff --git a/doc/user/campaigns/managing_access.md b/doc/user/campaigns/managing_access.md
new file mode 100644
index 000000000000..869d5ac50ac0
--- /dev/null
+++ b/doc/user/campaigns/managing_access.md
@@ -0,0 +1,81 @@
+# Managing access to campaigns
+
+You can customize access to a campaign and propose changes to repositories with varying permission levels. Other people see the campaign's proposed changes to a repository if they can view that repository; otherwise, they can see only limited, non-identifying information about the change.
+
+## Permission levels for campaigns
+
+Any person with a user account can create a campaign.
+
+The permission levels for a campaign are:
+
+- **Read:** For people who need to view the campaign.
+- **Admin:** For people who need full access to the campaign, including editing, closing, and deleting it.
+
+To see the campaign's proposed changes on a repository, a person *also* needs read access to that specific repository. Read or admin access on the campaign does not (by itself) entitle a person to viewing all of the campaign's changes. For more information, see "[Repository permissions for campaigns](#repository-permissions-for-campaigns)".
+
+Site admins have admin permissions on all campaigns.
+
+### Campaign access for each permission level
+
+Campaign action | Read | Admin
+--------------- | :--: | :----:
+View campaign name and description