GERRIT
GERRIT
Gerrit is a web-based code review tool built on top of the git source code management system. Many open-source(and so OpenStack) projects use it to manage how contributions get reviewed and merged.
THE FLOW OF A CHANGE.
| Step | Tool | Purpose |
| 1 | Git | You write your code and commit locally |
| 2 | Gerrit | You then submit your change to be reviewed by others |
| 3 | Zuul CI | Runs automatic tests on your change |
| 4 | Reviewers(human) | Approve or request changes |
| 5 | Gerrit | Merges your change |
MORE ABOUT THE REVIEWERS
Code review is someone looking at the code, ensuring it meets the project guidelines, intent etc.
CODE REVIEW SCORES
Once the reviewer has looked over the changes and needs to complete reviewing the submission. They click the review button which allows the to enter a code review label and message.
CODE REVIEW LABEL
This a vote the reviewer gives for your work. +2 or -2 levels are allowing or blocking the change. +1 or -1 level are just an opinion. in order for a change to be accepted it must have at least one +2 and no -2 votes. 0 is a neutral / no review.
AFTER REVIEW
After you submit your change (patchset), Gerrit waits for two main signals.
- Human approval:
- At least one core reviewer gives a +2
- Other reviewers may give +1s or comments
- Automated verification.
- Zuul CI runs a full set of tests.
- When successful, Gerrit adds a verified +1 label automatically
So code review +2 and verified +1, Gerrit automatically merges your change to the main branch.
LEARNING THE GERRIT WORKFLOW IN THE OPENDEV SANDBOX
Before that some key terms are important.
OpenDev. OpenDev is the collaborative development platform that hosts code for OpenStack. It is like GitHub but for OpenStack.
Launchpad. It is a user identity and project management system used by Ubuntu and OpenStack. It is important for developer identity and how you log in to Gerrit.
Ubuntu One. A single sign-on (SSO) service that Launchpad uses for authentication. It is like “sign in with google” but for Ubuntu ecosystem.
Git. Version control system for tracking code changes.
And finally Gerrit the code review platform for OpenDev projects.
MY EXPERIENCE WITH LEARNING THE GERRIT WORKFLOW
My targets for this practice are to:
- learn how to make and submit a patch.
- how Gerrit handles my submission
- How to update or abandon my patch
I realize before starting the practice, I need:
- git and git-review installed
- Launchpad account for Gerrit login
- Decided on Code environment. Terminal only eg with vim or vs code + terminal. (I am a beginner and decided for vs code + in terminal).
STEPS
- I installed git and git-review by running.
sudo apt install git git-review -y
- I then signed up to Launchpad, selecting no ubuntu one account.
- The next step is to setup SSH key. This way I can have a secure access to the remote servers without having to retype a password every time.
- Check if I already have an SSH key
ls ~/.ssh/id_rsa.pubI get an error no such file. So I don’t have an SSH key
- Generate a new SSH key with the email I used for launchpad.
ssh-keygen -t rsa -b 4096 -C "my email"
- Copy my public key. I confirmed the keys were created with
ls ~/.ssh/
There was a private and public key. I then cat the public key and copied the output.
- Go to Gerrit, sign in using Launchpad credentials and same username. Then navigate to settings, SSH public keys and paste the id_rsa.pub public key.
- Test connection with
ssh -p 29418 your-username@review.opendev.orgYou should see “welcome to Gerrit Code Review”
- Check if I already have an SSH key
- I then cloned the sandbox repo and cd into the repo.
git clone https://opendev.org/opendev/sandbox cd sandbox
- The next step was to configure git with the same credentials I used for Gerrit (Launchpad)
git config user.name " " git config user.email " " git config core.editor "code --wait"
- I then configured git-review so that it knows about Gerrit.
git review -s
- I then branched out from the master branch, created a file with some content, staged my only that file with git add.
- On git commit , a tab for the commit message opened so i could edit the commit message. I then submitted my first patch to gerrit.

here is the link for my first change submitted for review https://review.opendev.org/c/opendev/sandbox/+/963812
SECOND PATCH
- On the same git branch, I made a second file, my_2nd_README.md. I then staged only this file with git add. But to submit the new patchset to the same change I used,
git commit -a --amend
Link for second patch
https://review.opendev.org/c/opendev/sandbox/+/963812

I can abandon the change by using the abandon button.
This was a good introduction to the Gerrit workflow and can’t wait to make a real contribution.