Before diving into the technical part of campaigns, make sure to read up on what code campaigns are, what it's not and what we want it to be:
- Start by reading through the code change management product page
- IMPORTANT: Watch the videos! At the bottom of that page, you'll find two demo videos. A lot of our work aims to reproduce what you can see in these videos — in a scalable way that supports multiple code hosts. Make sure to watch these videos!
- Take a look at the sequence of milestones to get a high-level overview of what we did so far and what still needs to be done
- Read through the user documentation.
- Run
./enterprise/dev/start.sh— Wait until all repositories are cloned. - Follow the user guide on creating campaigns. Remember: If you create a campaign, you're opening real PRs on GitHub. Make sure only testing repositories are affected. If you create a large campaign, it takes a while to preview/create but also helps a lot with finding bugs/errors, etc.
The code campaigns feature introduces a lot of new names, GraphQL queries and mutations and database tables. This section tries to explain the most common names and provide a mapping between the GraphQL types and their internal counterpart in the Go backend.
| GraphQL type | Go type | Database table | Description |
|---|---|---|---|
Campaign |
campaigns.Campaign |
campaigns |
A campaign is a collection of changesets on code hosts. The central entity. |
ExternalChangeset |
campaigns.Changeset |
changesets |
Changeset is the unified name for pull requests/merge requests/etc. on code hosts. |
PatchSet |
campaigns.PatchSet |
patch_sets |
A patch set is a collection of patches that will be applied by creating and publishing a Campaign. A campaign has one patch set. |
Patch |
campaigns.Patch |
patches |
A patch for a repository that can be turned into a changeset on a code host. It belongs to a patch set, which has multiple patches, one per repository. |
| - | campaigns.ChangesetJob |
changeset_jobs |
It represents the process of turning a Patch (GraphQL)/campaigns.Patch (Go) into a Changeset on the code host. It is executed asynchronously in the background when a campaign is created with a patch set. |
ChangesetEvent |
campaigns.ChangesetEvent |
changeset_events |
A changeset event is an event on a code host, e.g. a comment or a review on a pull request on GitHub. They are created by syncing the changesets from the code host on a regular basis and by accepting webhook events and turning them into changeset events. |
(To re-generate the diagram from the campaigns_database_layout.dot file with Graphviz, run: dot -Tsvg -o campaigns_database_layout.svg campaigns_database_layout.dot.)
- Read through
./cmd/frontend/graphqlbackend/campaigns.goto get an overview of the campaigns GraphQL API. - Read through
./internal/campaigns/types.goto see all campaigns-related type definitions. - Compare that with the GraphQL definitions in
./cmd/frontend/graphqlbackend/schema.graphql. - Start reading through
./enterprise/internal/campaigns/resolvers/resolver.goto see how the main mutation are implemented (look atcreatePatchSetFromPatchesandcreateCampaignto see how the two main operations are implemented). - Then start from the other end,
enterprise/cmd/repo-updater/main.go, and see how the enterpriserepo-updaterusescampaigns.Syncerto syncChangesets.
The campaigns feature requires creating changesets (PRs) on code hosts. If you are not part of the Sourcegraph organization, we recommend you create dummy projects to safely test changes on so you do not spam real repositories with your tests. If you are part of the Sourcegraph organization, we have an account set up for this purpose.
To use this account, follow these steps:
- Find the GitHub
sd9user in 1Password - Copy the Campaigns Testing Token
- Change your
dev-private/enterprise/dev/external-services-config.jsonto only contain a GitHub config with the token, like this:
{
"GITHUB": [
{
"authorization": {},
"url": "https://github.com",
"token": "<TOKEN>",
"repositoryQuery": ["affiliated"]
}
]
}