Skip to main content
Version: TeamForge 24.0

Set up Git—Slack Integration

Gerrit has a plugin that lets you publish certain Gerrit events to a Slack channel. For more information, see Gerrit's Slack Integration Plugin documentation.

Install the Gerrit's Slack Integration Plugin and do the following to publish Gerrit events to a Slack channel:

  1. Create a Slack App and Webhook URL
  2. Configure the Slack Integration Gerrit Plugin with the Webhook URL

Let us go through these procedures step-by-step.

Create a Slack App and Webhook URL

  1. Log on to your Slack account. Skip this step if you are logged on already.

  2. Create a Slack App. Skip this step if you already have an app and want to use that to integrate with Gerrit.

  3. Go to the Slack Apps List page and click the Gerrit app.

  4. Select Basic Information from the Settings pane on the left. Click Add Features and Functionality to expand the pane.

  5. Click Incoming Webhooks.

  6. Click the Activate Incoming Webhooks toggle button to turn it on.

  7. Click Add New Webhook to Workspace.

  8. Select the Slack channel where you want your Gerrit notifications posted and click Allow.

    A success message appears in your Slack channel.

You have now configured the Webhook URL and this URL is bound to your Slack channel. Gerrit event data posted to this Webhook URL posts a message to the Slack channel.

The Webhook URL for this Slack channel and a sample CURL request to post data to the Webhook URL can be found at the bottom of the page. Keep this Webhook URL handy for later use when you in Gerrit. You can use the CURL command on your CLI to verify that the Webhook URL is indeed emptying itself on the configured Slack channel.

Configure the Slack Integration Gerrit Plugin

The Gerrit's Slack Integration Plugin is configured via a Gerrit project-specific configuration file. In other words, you must add the Slack channel's name, Webhook URL, and so on to this configuration file, which is the Gerrit project’s project.config file on the refs/meta/config branch of the project.

Here's a sample project.config file.

[plugin "slack-integration"]
channel = gerrit-post-hackathon-test
enabled = true
publish-on-patch-set-created = true
webhookurl = https://hooks.slack.com/services/T02GN6UQX/B020ZN6/vMrGO

This sample configuration sends notifications for Gerrit events such as patch-set-creation, Removing WIP, Review comment add (including Verify and Code-Review votes), Reviewer add, and Review merge.

note

This sample configuration sends no notification when you make a private review public.

Now, if you create a review in this repository, we should see a message from Gerrit in the Slack channel.

Points to Consider

  • ignore: A dotall enabled regular expression pattern—when matches against a commit message—prevents the publishing of patchset created event's messages.
  • ignore-wip-patch-set: Can be set to true to prevent Slack notifications regarding a work-in-progress change.
  • ignore-comment-author: Regular expression pattern—when matches against the comment author username—prevents the publishing of comment added event's messages.
  • publish-on-reviewer-added: Set to false to prevent a notification when a reviewer is added to a review.
  • Sometimes, it may take time for the Gerrit configuration changes to be applied to the repository. In such a case, force-refresh the repository. For example, here's a CURL request to force-refresh a repository with reps1022 as its repository ID in TeamForge:
curl -k -X GET https://gerrit.collab.net/api/refresh/repositories/reps1022

The CURL option -k is added to avoid SSL error. If not CURL, just opening the above repository URL in a browser's address bar can refresh the repository. Opening the repository URL in a browser is the easiest way and if you are using Gerrit over the browser, you can avoid the SSL error too.