Gerrit code review

Stay organized with collections Save and categorize content based on your preferences.

The Google Agency Code Git repo you are using includes Gerrit code review capabilities, a web based code review and repository management tool.

A code review will be useful during the development process, or for project stakeholders to audit and comment on changes that you’ve made. Depending on the project, a full review may be mandatory to ensure code complies with Google style guides. Regardless, it is still a good practice to follow this guidance.

You will learn how to:

  • Create code reviews using Gerrit
  • Action comments / changes on Gerrit reviews
  • Submit approved changes to your Git repo

Setup

You will be provided with a Google Agency Code Git repo link to use.

Add the following commit hooks.

curl -Lo \`git rev-parse --git-dir`/hooks/commit-msg
\https://gerrit-review.googlesource.com/tools/hooks/commit-msg ;
\chmod +x `git rev-parse --git-dir`/hooks/commit-msg
  1. Create a new branch in the repo, this will be used for merging accepted code changes into.
  2. If relevant, the new branch should contain all original code (previously approved code that does not need to be reviewed).
  3. Push that branch (without any changes on it) to origin.

    git push origin {branch name}
    

Workflow

  1. Once set up the workflow of committing code to be reviewed, commenting / changes, and submitting when ready, can be followed.
  2. Use Git to add files that will be reviewed.
  3. It is best practice to separate JS, CSS and Static files into separate reviews, so at this stage only commit the relevant files to be reviewed (repeat workflow steps 1 - 4 to setup the other reviews).
  4. Run a strict Linter on relevant files, and fix all errors. For example, using the Closure Javascript Linter --strict command line flag.
  5. Commit the files to be reviewed.
  6. Once committed push the changes and email them to the reviewer.

    git push origin HEAD:refs/for/{branch name}%r={email}
    

    Every time you update the commit with changes run this command, a Change-Id will be generated to identify the commit that's being reviewed.

    The reviewer may make comments on code that needs to change, once these comments have been actioned you can add them in a separate commit and then rebase them together…

    git rebase -i HEAD~1
    

    A interactive console will let you meld the new commit with the old one, choose option fixup.

    When ready update the reviewer by marking the comments as resolved, and pushing them in step 4).

    When resolved the reviewer will reply with a ‘Looks good to me, approved’. Once approved submit the final update.