Skip to content

Commit

Permalink
Merge pull request #6 from amboar/master
Browse files Browse the repository at this point in the history
Pull request for Tracking ID search and Optional Markup
  • Loading branch information
hobbs committed Mar 15, 2012
2 parents b9a78b3 + ed135d8 commit fdfaa49
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
24 changes: 18 additions & 6 deletions hooks/jirret-process-hook
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ url = config.get('jira', 'url')
gerrit_cmd = config.get('jira', 'gerritcmd')
custom_field = config.get('jira', 'custom_field')

rpc = xmlrpclib.ServerProxy(url)
auth = rpc.jira1.login(user, password)

use_trackingid_option = ('jira', 'use_trackingid')
use_trackingid = config.get(*use_trackingid_option).lower() == 'true' \
if config.has_option(*use_trackingid_option) else False

enable_quotes_option = ('jira', 'enable_quotes')
enable_quotes = config.get(*enable_quotes_option).lower() == 'true' \
if config.has_option(*enable_quotes_option) else True

rpc = xmlrpclib.ServerProxy(url)
auth = rpc.jira1.login(user, password)

def showUsage():
print '\nNormal hook usage: ' + sys.argv[0] + ' --action [new|merged|abandoned] --change <change id> --commit <git hash> --change-url <url to change>'
Expand Down Expand Up @@ -60,9 +65,14 @@ def updateTicket(what, id, hash, url, who, branch):

issues = []
print projects
issue_needle = '(%s-[0-9]+)'
issue_haystack = subject
if use_trackingid:
issue_needle = ' +id: +' + issue_needle
issue_haystack = out
for p in projects:
print issues
matches = re.findall('(' + p + '-[0-9]+)+', subject)
matches = re.findall(issue_needle % p, issue_haystack)
print matches
for m in matches:
issues.append(m)
Expand All @@ -83,14 +93,16 @@ def updateTicket(what, id, hash, url, who, branch):

if (len(url) > 0):
message += url
message += '{quote}'
if (enable_quotes):
message += '{quote}'
message += '\nSubject: ' + subject + '\n'
message += 'Project: ' + gerrit_prj + '\n'
message += 'Branch: ' + branch + '\n'
message += 'ChangeId: ' + id + '\n'
if (len(hash) > 0):
message += 'Commit: ' + hash+ '\n'
message += '{quote}'
if (enable_quotes):
message += '{quote}'

print 'Issues: ' + str(issues)
for i in issues:
Expand Down
7 changes: 7 additions & 0 deletions jirretconfig.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ custom_field=
# if ommited, you must run "./hooks/jirret-process-hook update-projects" after setting up the above
# credentials to automatically fill in the projects list
projects=

# Set to 'true' if you'd like Jirret to search for Gerrit tracking IDs rather
# than in the subject line for your issue IDs
use_trackingid=false

# Set to false to disable {quote} markers surrounding comments
enable_quotes=true

0 comments on commit fdfaa49

Please sign in to comment.