Gerrit Support in Teamscale

Posted on 09/19/2017 by Andi Scharfstein

Since release version 3.4, Teamscale has offered support for Gerrit. Over the last months, we have steadily worked to extend and improve this support even further to cover all conceivable use cases. In this post, I am going to show you how this support looks like to the Teamscale end user.

When you create a project, you can connect to your Gerrit instance directly. Teamscale will import the code from any specified Gerrit project, similar to a normal Git repository.

Adding a Gerrit connector

The main difference to a normal Git repository is a number of additional “review branches” you will see in the Teamscale branch dropdown. These correspond to Gerrit changesets. Teamscale imports and analyzes these changesets, even if they are not merged back into master yet.

Gerrit branches

Teamscale creates one review branch per changeset:

Gerrit changeset

Corresponding Teamscale branch

One big advantage of this branch-like treatment is that you can actually track which commit introduced which changes, including findings you may have introduced or removed. Even though you only amend a single commit to interact with Gerrit, Teamscale treats each amendment as a separate commit. The unfortunate naming of the branches is due to the fact that aside from its ID, Gerrit doesn’t associate any other fixed/unchangeable information with a change.

Teamscale does not just analyze the commits, it can also interact with Gerrit to vote on changes. Specifically, Teamscale will hand any change set a +1 (should merge) vote when that change set does not introduce any new findings. If a change set introduces a new finding, Teamscale will vote -1 (merge discouraged). However, this behaviour is configurable: You can disable voting altogether, or you can choose to ignore yellow (“uncritical”) findings in the vote. In the given example, the three commits introduce the following findings:

  1. first commit: no finding
  2. second commit: a yellow finding (unused variable)
  3. third commit: a red finding (cloned method)

Note how the vote turns to -1 only on the red finding.

Code-Review votes

If you look closely at the last vote, you may notice that Teamscale also comments on the file itself so you can navigate from the Gerrit file view directly to the respective Teamscale finding (of course, this behaviour can be turned off as well). Each vote also contains a link to the complete delta of all findings introduced and removed in the respective change set.

Gerrit file comments

We hope you find this functionality useful! If you want to try it out, you can get your free Teamscale evaluation copy right here.