Commits

Kelsey Hightower committed 6da6d8b

Removing hgroundup patch

Comments (0)

Files changed (2)

hgroundup

-# HG changeset patch
-# Parent 9863f0c15be9b16315fcaf70b3e997d6901d13b7
-New hook to update Roundup issues based on commit messages
-
-diff -r 9863f0c15be9 hgroundup.py
---- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/hgroundup.py	Mon Mar 07 10:23:16 2011 -0500
-@@ -0,0 +1,150 @@
-+"""Mercurial hook to update a Roundup issue.
-+
-+Update a Roundup issue via email for changesets where commit messages
-+match the following pattern:
-+
-+    #XXXX Commit message.
-+
-+X is an interger [0-9]
-+
-+To use this hook, include the following in hgrc:
-+
-+    [hooks]
-+    pretxnchangegroup.update_issue = python:hgroundup.update_issue
-+
-+    [hgroundup]
-+    repo = http://hg.python.org/cpython/
-+    toaddr = roundup-admin@example.com
-+    mailrelay = 127.0.0.1
-+"""
-+import re
-+import smtplib
-+
-+from string import Template
-+from email.mime.text import MIMEText
-+
-+
-+_ISSUE_PATTERN = (r"^#(?P<issue_id>[0-9]+)\s(?P<commit_msg>[\w\s]+\w)\s*"
-+                  r"(?:\[(?P<properties>.*)\])*")
-+_COMMENT_TEMPLATE = "${commit_msg}\n${changeset_url}"
-+_issues = {}
-+
-+
-+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')
-+    toaddr = ui.config('hgroundup', 'toaddr')
-+    mailrelay = ui.config('hgroundup', 'mailrelay', default='127.0.0.1')
-+    start = repo[node].rev()
-+
-+    for rev in xrange(start, len(repo)):
-+        ctx = repo[rev]
-+        data = _is_roundup_issue(ctx.description())
-+        ui.debug(str(data) + '\n')
-+        if data:
-+            params = {}
-+            params['changeset_url'] = repo_url + str(ctx)
-+            params['commit_msg'] = data['commit_msg']
-+            _add_issue(data['issue_id'], data['properties'],
-+                       _create_comment(params))
-+    if _issues:
-+        try:
-+            _send_comments(mailrelay, toaddr, _issues, ctx)
-+            ui.status("Sent email to roundup at " + toaddr + '\n')
-+        except:
-+            # make sure an issue updating roundup does not prevent an
-+            # otherwise successful push.
-+            ui.warn("Sending email to roundup at %s failed\n" % toaddr)
-+    else:
-+        ui.debug("No issues to send to roundup\n")
-+    return False
-+
-+
-+def _is_roundup_issue(msg):
-+    """Check the commit message for an issue ID.
-+    """
-+    try:
-+        match = re.match(_ISSUE_PATTERN, msg)
-+        return match.groupdict()
-+    except:
-+        return None
-+
-+
-+def _create_comment(params):
-+    return Template(_COMMENT_TEMPLATE).substitute(params)
-+
-+
-+def _add_issue(issue_id, properties, comment):
-+    global _issues
-+    if issue_id in _issues:
-+        _issues[issue_id]['comments'].append(comment)
-+        if properties:
-+            _add_replace_properties(_issues[issue_id]['properties'], properties)
-+    else:
-+        _issues[issue_id] = {}
-+        _issues[issue_id]['comments'] = [comment]
-+        _issues[issue_id]['properties'] = []
-+        if properties:
-+            _add_replace_properties(_issues[issue_id]['properties'], properties)
-+
-+
-+def _add_replace_properties(oldprops, newprops):
-+    """Add or replace roundup properties. Insure there are no duplicate
-+    properties defined, and replace old property values with new ones,
-+    last value wins
-+
-+    :params oldprops: the global issues[properties] list
-+    :params newprops: new roundup properties string
-+                      (i.e. [nosy=richard,cliff;priority=urgent])
-+    """
-+    props = []
-+    # multiple roundup properties can be specified at once using
-+    # the [property=value;property=value] syntax. We need to split
-+    # them here to make it easier to compare later.
-+    newprops = newprops.split(';')
-+    for newprop in newprops:
-+        split_newprop = newprop.split('=')
-+        if oldprops:
-+            for oldprop in oldprops:
-+                split_oldprop = oldprop.split('=')
-+                if split_newprop == split_oldprop:
-+                    continue
-+                # if both property keys are equal remove the old property
-+                # and stage the new one. Last value wins.
-+                elif split_newprop[0] == split_oldprop[0]:
-+                    oldprops.remove(oldprop)
-+                    props.append(newprop)
-+                else:
-+                    props.append(newprop)
-+        else:
-+            props.append(newprop)
-+    # update old properties
-+    oldprops.extend(props)
-+
-+
-+def _send_email(mailrelay, fromaddr, toaddr, msg):
-+    s = smtplib.SMTP(mailrelay)
-+    s.sendmail(fromaddr, toaddr, msg)
-+    s.quit()
-+
-+
-+def _send_comments(mailrelay, toaddr, issues, ctx):
-+    """Update the Roundup issue with a comment and changeset link.
-+    """
-+    fromaddr = ctx.user()
-+    for issue in issues:
-+        if 'properties' in issues[issue] and issues[issue]['properties']:
-+            _props = ';'.join(issues[issue]['properties'])
-+            props = '[%s]' % _props
-+        else:
-+            props = ''
-+        msg = MIMEText('\n\n'.join(issues[issue]['comments']))
-+        msg['From'] = fromaddr
-+        msg['To'] = toaddr
-+        msg['Subject'] = "[issue%s] new commit %s" % \
-+                         (issue.lstrip('#'), props)
-+        _send_email(mailrelay, fromaddr, toaddr, msg.as_string())
-hgroundup
 # Placed by Bitbucket