[Python-checkins] hooks: Lots of cosmetic changes (original) (raw)
local-hg python-checkins at python.org
Tue Mar 8 20:59:34 CET 2011
- Previous message: [Python-checkins] devguide: Adapt server-side clone instructions to the new UI
- Next message: [Python-checkins] #8594: fix ResourceWarning in test_ftplib.py - patch by Nadeem Vawda.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
http://hg.python.org/hooks/rev/931248abb746 changeset: 57:931248abb746 user: Antoine Pitrou <solipsis at pitrou.net> date: Tue Mar 08 20:59:34 2011 +0100 summary: Lots of cosmetic changes
files: hgroundup.py
diff --git a/hgroundup.py b/hgroundup.py --- a/hgroundup.py +++ b/hgroundup.py @@ -30,57 +30,83 @@ import re import smtplib import posixpath +import traceback
from string import Template from email.mime.text import MIMEText
-VERBS = r'(?:\b(?Pclose[sd]?|closing|fixe[sd]|fixing|fix)\s+)?'
+from mercurial.templatefilters import person
+
+VERBS = r'(?:\b(?Pclose[sd]?|closing|)\s+)?'
ISSUE_PATTERN = re.compile(r'%s(?:#|\bissue|\bbug)\s*(?P[0-9]{4,})'
% VERBS, re.I)
-COMMENT_TEMPLATE = "${commit_msg}\n${changeset_url}"
+COMMENT_TEMPLATE = """
+New changeset changesetidby{changeset_id} by changesetidbyauthor in branch '${branch}':
+${commit_msg}
+${changeset_url}
+"""
-def update_issue(ui, repo, node, **kwargs): +def update_issue(*args, **kwargs):
- try:
_update_issue(*args, **kwargs)
- except:
traceback.print_exc()
raise
- +def _update_issue(ui, repo, node, **kwargs): """Update a Roundup issue for corresponding changesets. Return True if updating the Roundup issue fails, else False. """
- repo_url = ui.config('hgroundup', 'repo')
repourl = ui.config('hgroundup', 'repourl')
if not repourl:
repourl = posixpath.join(ui.config('web', 'baseurl'), 'rev/')
fromaddr = ui.config('hgroundup', 'fromaddr') toaddr = ui.config('hgroundup', 'toaddr') mailrelay = ui.config('hgroundup', 'mailrelay', default='127.0.0.1')
for var in ('repourl', 'fromaddr', 'toaddr'):
if not locals()[var]:
raise RuntimeError(
'roundup hook not configured properly,\nplease '
'set the "%s" property in the [hgroundup] section'
% var)
start = repo[node].rev()
issues = {}
for rev in xrange(start, len(repo)): ctx = repo[rev]
description = ctx.description()
description = ctx.description().strip() match = ISSUE_PATTERN.search(description)
ui.warn('match in commit msg: %s\n' % (match and match.groupdict() or 'no'))
ui.debug('match in commit msg: %s\n' % (match and match.groupdict() or 'no')) if not match: continue data = match.groupdict() comment = Template(COMMENT_TEMPLATE).substitute({
'changeset_url': posixpath.join(repo_url, str(ctx)),
'commit_msg': description,
'author': person(ctx.user()),
'branch': ctx.branch(),
'changeset_id': str(ctx),
'changeset_url': posixpath.join(repourl, str(ctx)),
if issues: try:'commit_msg': description.splitlines()[0], }) add_comment(issues, ctx.user(), data, comment)
send_comments(mailrelay, toaddr, issues)
ui.status("Sent email to roundup at " + toaddr + '\n')
send_comments(mailrelay, fromaddr, toaddr, issues)
ui.status("sent email to roundup at " + toaddr + '\n') except Exception, err: # make sure an issue updating roundup does not prevent an # otherwise successful push.
ui.warn("Sending email to roundup at %s failed: %s\n" %
else:ui.warn("sending email to roundup at %s failed: %s\n" % (toaddr, err))
ui.debug("No issues to send to roundup\n")
return Falseui.debug("no issues to send to roundup\n")
def add_comment(issues, user, data, comment): """Process a comment made in a commit message."""
- key = (data['issue_id'], user)
- key = data['issue_id'] if key in issues: issues[key]['comments'].append(comment) else: @@ -91,19 +117,19 @@ 'resolution': 'fixed' })
-def send_comments(mailrelay, toaddr, issues): +def send_comments(mailrelay, fromaddr, toaddr, issues): """Update the Roundup issue with a comment and changeset link."""
- for (issue_id, user), data in issues.iteritems():
props = ''
if data['properties']:
props = ' [%s]' % ';'.join('%s=%s' % x
for x in data['properties'].iteritems())
msg = MIMEText('\n\n'.join(data['comments']))
msg['From'] = user
msg['To'] = toaddr
msg['Subject'] = "[issue%s]%s" % (issue_id, props)
import sys
print >>sys.stderr, msg['Subject']
s = smtplib.SMTP(mailrelay)
s.sendmail(user, toaddr, msg.as_string())
- s = smtplib.SMTP(mailrelay)
- try:
for issue_id, data in issues.iteritems():
props = ''
if data['properties']:
props = ' [%s]' % ';'.join('%s=%s' % x
for x in data['properties'].iteritems())
msg = MIMEText('\n\n'.join(data['comments']))
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "[issue%s]%s" % (issue_id, props)
s.sendmail(fromaddr, toaddr, msg.as_string())
- finally: s.quit()
-- Repository URL: http://hg.python.org/hooks
- Previous message: [Python-checkins] devguide: Adapt server-side clone instructions to the new UI
- Next message: [Python-checkins] #8594: fix ResourceWarning in test_ftplib.py - patch by Nadeem Vawda.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]