Created
July 20, 2010 22:15
-
-
Save matagus/483686 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from mercurial import util | |
import re | |
def check_references(*args, **kwargs): | |
""" | |
Checks that commit message contains a reference to or closes an issue. | |
Useful when using Redmine. | |
Usage in .hgrc: | |
[hooks] | |
pretxncommit = python:/path/to/this/file.py:check_references | |
""" | |
repo = kwargs["repo"] | |
node_id = kwargs["node"] | |
changeset = repo[node_id] | |
description =changeset.description() | |
DESCRIPTION_CHECKS = ( | |
"this references #\d+", "this closes #\d+", | |
) | |
lets_commit = False | |
for regexp in DESCRIPTION_CHECKS: | |
if re.search(regexp, description, re.I): | |
# message is ok, let's commit! | |
lets_commit = True | |
break | |
if lets_commit: | |
return False | |
# this will rollback the changeset | |
raise util.Abort("Please reference some issue using "\ | |
"'This references #<issue>' or close it using 'This closes #<issue>'.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment