Setting up Slack notifications

Slack notifications are supported via webhooks. Webhooks are special URLs that Sourcegraph's Code Monitoring can call in order to send a message to a Slack channel when there are new search results for a query. In order to use Slack notifications, you must first create a Slack application in your organization's Slack workspace, add a webhook for a Slack channel within that application, and then configure a code monitor in Sourcegraph to use that webhook's URL.

Prerequisites

  • You must have the experimental feature flag experimentalFeatures.codeMonitoringWebHooks set to true in your Sourcegraph settings
  • You must have permission to create apps inside of your organization's Slack workspace

Creating a Slack webhook

  1. Navigate to https://api.slack.com/apps and sign in to your Slack account if necessary.
  2. Click on the "Create an app" button.
  3. Create your app "From scratch".
  4. Give your app a name and select the workplace you want notifications sent to.
  5. Once your app is created, click on the "Incoming Webhooks" in the sidebar, under "Features".
  6. Click the toggle button to activate incoming webhooks.
  7. Scroll to the bottom of the page and click on "Add New Webhook to Workspace".
  8. Select the channel you want notifications sent to, then click on the "Allow" button.
  9. Your webhook URL is now created! Click the copy button to copy it to your clipboard.

Configuring a code monitor to send Slack notifications

  1. In Sourcegraph, click on the "Code Monitoring" nav item at the top of the page.
  2. Create a new code monitor or edit an existing monitor by clicking on the "Edit" button next to it.
  3. Go through the standard configuration steps for a code monitor and select action "Send Slack message to channel".
  4. Paste your webhook URL into the "Webhook URL" field.
  5. Click on the "Continue" button, and then the "Save" button.