Configuring user credentials

In order to publish changesets with campaigns, you need to add a personal access token for each code host that your campaigns interact with. These tokens are used by Sourcegraph to create and manage changesets as you, and with your specific permissions, on the code host.

Requirements

  • Sourcegraph instance with repositories in it. See the “Quickstart” guide on how to setup a Sourcegraph instance.

Adding a personal access token

Adding personal access tokens is done through the the Campaigns section of your user settings:

  1. From any Sourcegraph page, click on your avatar at the top right of the page.
  2. Select Settings from the dropdown menu.
  3. Click Campaigns on the sidebar menu.

You should now see a list of the code hosts that are configured on Sourcegraph. Code hosts with tokens configured are indicated by a green tick, while code hosts without tokens have an empty red circle next to them.

To add a token for a code host, click on the Add token button next to its name. This will display an input modal like the following:

An input dialog, titled "Github campaigns token for https://github.com", with an input box to type or paste a token and a list of scopes that must be enabled on the token, which are repo, read:org, user:email, and read:discussion

To create a personal access token for a specific code host provider, please refer to the relevant section for “GitHub”, “GitLab”, or “Bitbucket Server”. Once you have a token, you should paste it into the Sourcegraph input shown above, and click Add token.

Once this is done, Sourcegraph should indicate that you have a token with a green tick:

A list of code hosts, with GitHub indicating that it has a token and the other hosts indicating that they do not

GitHub

In addition to the below, you should refer to GitHub’s documentation on creating a personal access token.

Sourcegraph requires the repo, read:org, user:email, and read:discussion scopes to be enabled on the user token. This is done by selecting the relevant checkboxes when creating the token:

The GitHub token creation page, with the repo scope selected

GitLab

In addition to the below, you should refer to GitLab’s documentation on creating a personal access token.

Sourcegraph requires the api, read_repository, and write_repository scopes to be enabled on the user token. This is done by selecting the relevant checkboxes when creating the token:

The GitLab token creation page, with the api, read_repository, and write_repository scopes selected

Bitbucket Server

In addition to the below, you should refer to Bitbucket Server’s documentation on creating a personal access token.

Sourcegraph requires the access token to have the write permission on both projects and repositories. This is done by selecting the Write level in the Projects dropdown, and letting it be inherited by repositories:

The Bitbucket Server token creation page, with Write permissions selected on both the Project and Repository dropdowns

Removing a personal access token

Removing personal access tokens is done through the the Campaigns section of your user settings. To access this page, follow these instructions (also shown in the video below):

  1. From any Sourcegraph page, click on your avatar at the top right of the page.
  2. Select Settings from the dropdown menu.
  3. Click Campaigns on the sidebar menu.

You should now see a list of the code hosts that are configured on Sourcegraph. Code hosts with tokens configured are indicated by a green tick, while code hosts without tokens have an empty red circle next to them.

To remove a personal access token for a code host, click Remove next to that code host. The code host’s indicator will change to an empty red circle to indicate that no token is configured for that code host:

A list of code hosts, with all code hosts indicating that they do not have a token