Add Git hooks to close review requests automatically and to check if each review request is approved.

Review Request #5403 — Created Feb. 5, 2014 and submitted — Latest diff uploaded

Information

Review Board
master
6d9cdcf...

Reviewers

There are two Git hook scripts in this review request.

The first is a Git post-receive hook script (git-hook-set-submitted) that will automatically close review requests as "submitted" after a push.

The second is a Git pre-receive hook script (git-hook-check-approval) that checks if each review request corresponding to a commit has been approved. A commit that has no corresponding review request is marked as being unapproved (optional). If any of the checked commits is unapproved, it declines the push (optional).

In both, to determine which review requests should be processed, it scans through each commit's commit message for the following strings (case-insensitive): "Reviewed at <reviewboard_url>/r/<id>" or "Review request #<id>".

Created a local Git repository, added the hook, and tested different pushes from a cloned repository:

  • Commits with and without a review request ID in the commit message
  • Merge commits (3-way merge, fast-forward merge)
  • Branch deletion (no "fatal" error shows up)
  • Branch creation (1 branch with 2 initial commits -- all review requests are closed properly)
  • Commits referencing the same review request ID (close_review_request is executed only once, and the change description displays all commits that referenced that particular review request ID)
  • Commit pushed to multiple branches (e.g., someone commits on branch1, merges branch1 into master, pushes both branch1 and master -- see attached screenshot. close_review_request is executed once.)
  • Branch creation and commit pushed to multiple branches (e.g., someone creates branch1, commits on branch1, merges branch1 into master, pushes both branch1 and master)

All test cases above showed the expected behaviour.

Additionally, for the pre-receive hook:
- Commit with review request ID that is approved (push is accepted)
- Commit with review request ID that is not approved, due to open issues or a lack of "Ship It!"s (push is declined)
- Commit without a review request ID in the commit message (push is declined)
- Multiple commits, where one of the review requests is not approved (push is declined)
- Multiple commits, where all of the review requests are approved (push is accepted)
- Set REQUIRE_REVIEW_REQUESTS to False, and pushed a commit without a review request ID in the commit message (push is accepted)
- Set DECLINE_UNAPPROVED_PUSH to False, and pushed commits that are not approved (push is accepted)


    Loading...