- Added Files:
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
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)
Description | From | Last Updated |
---|---|---|
We should expand this top comment to describe the format used to reference the review requdest ids in the commit … |
SM smacleod | |
Take a look into rbtools.utils.process, we include an execute command which has some extra helpers, including allowing you to specify … |
SM smacleod | |
You should try to cut the summary down to one line. You could probably add the information about revserse order … |
SM smacleod | |
Style: These doc strings should generally be a single line summary, with a blank line, and then additional information. So, … |
SM smacleod | |
I'd prefer if we explicitly return None rather than having it happen due to no call to return. Maybe go … |
SM smacleod | |
This would probably look cleaner formatted as a list on multiple lines. See my previous comment about using rbtools' execute … |
SM smacleod | |
Nit: "each commit's commit message" is duped here. |
mike_conley | |
I think we generally put the imports before any const declarations. |
mike_conley | |
The "Reviewed at /r/" is really "Reviewed at <URL>/r/", right? |
chipx86 | |
Maybe mention that this can be customized if a different format is required. Given that, the regex should used named … |
chipx86 | |
Should have a 'r' prefix, like: REGEX = r'(....)' |
chipx86 | |
No blanke line here. |
chipx86 | |
No need for parens on the join string. |
chipx86 | |
The parameters should align. For logging calls, you don't need to use %. You can just pass the parameters as … |
chipx86 | |
No blank line here. |
chipx86 | |
No blank line here either. You can just collapse these into one conditional. |
chipx86 | |
Same comment about parens. |
chipx86 | |
Same comment about arguments. |
chipx86 | |
Two blank lines between top-level functions/classes/etc. |
chipx86 | |
This is really "Reviewed at <URL>/r/" |
chipx86 | |
Same comments about the regex. |
chipx86 | |
No blank line. |
chipx86 | |
Does this show the branch names, or just the SHAs? |
chipx86 | |
No need for parens. |
chipx86 | |
There's an extra blank line here. I think maybe we miscommunicated when you asked if files should end in a … |
david | |
Extra blank line. |
david |
-
-
We should expand this top comment to describe the format used to reference the review requdest ids in the commit message.
Speaking of which, maybe we should have the regex as a global up here so it can be customized easily.
-
I wonder if we could pull this information from the repositories ".reviewboardrc" file?
I don't think you should really spend a lot of time investigating this, or if it's even useful, just a thought.
-
Take a look into rbtools.utils.process, we include an execute command which has some extra helpers, including allowing you to specify the command as a list.
-
You should try to cut the summary down to one line. You could probably add the information about revserse order after a blank line.
-
Style: These doc strings should generally be a single line summary, with a blank line, and then additional information.
So, in this case:
"""Returns the review request ID referenced in the commit message.
We assume there is only one review request to be closed per commit. If
an ID cannot be found we returnNone
.
""" -
I'd prefer if we explicitly return
None
rather than having it happen due to no call to return.Maybe go with something like this?
review_request_id = (match and match.group(1)) or None return review_request_id
-
This would probably look cleaner formatted as a list on multiple lines. See my previous comment about using rbtools' execute function.
- Change Summary:
-
Added handling for new branches created in a push, and fixed issues raised in review.
- Summary:
-
[WIP] Add Git post-receive hook script to close review requests automatically[WIP] Add Git post-receive hook script to close review requests automatically.
- Testing Done:
-
~ Created a local Git repository, added the hook, and tested different pushes from a cloned repository:
~ 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) - - Commits referencing the same review request ID - - Repeated commits (e.g., someone commits on branch1, merges branch1 into master, pushes both branch1 and master -- refer to the attached screenshot) ~ For the last two, rbt close is executed once as expected, and the change description displays all the commits that referenced that particular review request ID.
~ - 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 (rbt close is executed once as expected, and the change description displays all commits that referenced that particular review request ID)
+ - Repeated commits (e.g., someone commits on branch1, merges branch1 into master, pushes both branch1 and master -- see attached screenshot. rbt close is executed once.)
+ - Branch creation and repeated commits (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.
- Change Summary:
-
- Refactored the Git post-receive hook script -- there is now a new 'hooks' module in rbtools. rbtools/hooks/common.py contains functions common to all hook scripts, and rbtools/hooks/git.py contains functions for Git hook scripts. (I had to add these files manually since this review request is under the Review Board repo.)
- Added a Git pre-receive hook script that checks if each review request corresponding to a commit has been approved.
- Resolved the open review issues.
- Summary:
-
[WIP] Add Git post-receive hook script to close review requests automatically.[WIP] Add Git hooks to close review requests automatically and to check if each review request is approved.
- Description:
-
~ This is a Git post-receive hook script that will automatically close review requests as "submitted" after a push. To determine which review request should be closed, it scans through each commit's commit message for the following strings (case-insensitive): "Reviewed at <reviewboard_url>/r/<id>" or "Review request #<id>".
~ 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>".
- Testing Done:
-
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 (rbt close is executed once as expected, and the change description displays all commits that referenced that particular review request ID)
- Repeated commits (e.g., someone commits on branch1, merges branch1 into master, pushes both branch1 and master -- see attached screenshot. rbt close is executed once.)
- Branch creation and repeated commits (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) - Diff:
-
Revision 3 (+112)
- Added Files:
-
-
-
Maybe mention that this can be customized if a different format is required.
Given that, the regex should used named groups for the results, instead of positional groups. You can do that with:
r'.... (?<id>\d+)'
And then later:
m.group('id')
-
-
-
-
The parameters should align.
For logging calls, you don't need to use
%
. You can just pass the parameters as parameters to the function. -
-
-
-
-
-
-
-
-
-
-
Oh, one more thing. I think this code would be better living in the RBTools tree. More accessible than pulling down the RB tree. It'll also help tie the hooks to RBTools versions more.
I didn't see any change yet for the RBTools modifications for the new the modules you made.
- Change Summary:
-
Created a new review request for the RBTools changes.
- Depends On:
-
- Removed Files:
- Change Summary:
-
Add option to specify regex flags, as suggested in /r/5543.
- Commit:
-
414077b883e1568713a7d60672dca3a14d83d243
- Testing Done:
-
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 (rbt close is executed once as expected, and the change description displays all commits that referenced that particular review request ID)
~ - Repeated commits (e.g., someone commits on branch1, merges branch1 into master, pushes both branch1 and master -- see attached screenshot. rbt close is executed once.)
~ - Branch creation and repeated commits (e.g., someone creates branch1, commits on branch1, merges branch1 into master, pushes both branch1 and master)
~ - 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)
- Change Summary:
-
Added instructions on how to install the hooks.
- Commit:
-
414077b883e1568713a7d60672dca3a14d83d243d15aa0e8976c7b1d1a26942373d0c0b0d97c8dc1
-
What do users see if they try to push but their push is denied because the review request isn't approved?
-
There's an extra blank line here. I think maybe we miscommunicated when you asked if files should end in a newline. Some editors don't add a \n at the very end of the file, but most do. It looks here like your files end in \n\n instead of just \n.
-