Gerrit Reviews and Automatic Topics
The more I use the combination of git-flow and gerrit as our code review process the more I feel I’d never want to use anything different.
As we continue to break up our projects into smaller repositories I find my change sets often cross repository boundaries.
When ever I find myself with a large, epic, cross-repository refactoring I find myself wanting a way to group the disparate reviews under a common “tag” to signify their interdependence - and it turns out Gerrit supports this via “topics”.
Traditionally we setup our repositories to push into gerrit with a for-review remote for the develop branch along the lines of:
[remote "for-review"]
url = gerrit:dev/$GIT_REPO_NAME
fetch = +refs/heads/*:refs/remotes/for-review/*
push = HEAD:refs/for/develop
Which means submitting reviews is a simple matter of running git push for-review. But if I want to submit a review with a topic defined, I need to modify my .git/config’s push reference, or write a long winded command line.
Being the lazy developer that I am, I followed wrote up a simple git-submit-review script to handle it all for me:
#!/bin/sh
url=$(git config --get remote.for-review.url)
push=$(git config --get remote.for-review.push)
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/feature/}
branch_name=${branch_name:-HEAD}
git push $url $push/$branch_name
echo "Open browser to: \
http://gerrit/#/q/status:open+topic:$branch_name,n,z \
to view topic reviews"
Sticking this on the path lets me run git submit-review and any commits will be pushed to gerrit, along with the current feature branch name as the topic.
Now, for each repository I’m working on, if I use the same feature name, such as TEST-102-some-epic-fix then all of those reviews will be grouped nicely together so I can just send that filtered search to a coworker.
Note: This works for Gerrit 2.5, by looking at documentation changes for the upcoming 2.6 release, the topic is set by appending %topic=TOPICNAME_ to the push reference.