← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/contributions-linkify-bugs into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/contributions-linkify-bugs into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/contributions-linkify-bugs/+merge/89403

I often look at https://dev.launchpad.net/Contributions when I'm trying to find a reference to some bit of work I did recently.  It would be easier to navigate if bug numbers in commit messages were rendered as links.  This branch makes it so.
-- 
https://code.launchpad.net/~cjwatson/launchpad/contributions-linkify-bugs/+merge/89403
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/contributions-linkify-bugs into lp:launchpad.
=== modified file 'utilities/community-contributions.py'
--- utilities/community-contributions.py	2012-01-01 03:10:25 +0000
+++ utilities/community-contributions.py	2012-01-20 10:00:34 +0000
@@ -305,6 +305,10 @@
 class ContainerRevision():
     """A wrapper for a top-level LogRevision containing child LogRevisions."""
 
+    # Regular expression based on that used by qa-tagger.
+    fixed_bug_re = re.compile(
+        r'(\[bugs?=)(\d+(?:,\s*\d+)*)(\])', re.IGNORECASE)
+
     def __init__(self, top_lr, branch_info):
         """Create a new ContainerRevision.
 
@@ -320,10 +324,21 @@
         """Add a descendant child of this container revision."""
         self.contained_revs.append(lr)
 
+    def format_fixed_bug_ids(self, text):
+        """Format any bug numbers in the given string as links."""
+        def format_bugs(match):
+            return (
+                match.group(1) +
+                re.sub(r'(\d+)', r'[[Bug:\1]]', match.group(2)) +
+                match.group(3))
+
+        return self.fixed_bug_re.sub(format_bugs, text)
+
     def __str__(self):
         timestamp = self.top_rev.rev.timestamp
         timezone = self.top_rev.rev.timezone
         message = self.top_rev.rev.message or "(NO LOG MESSAGE)"
+        message = self.format_fixed_bug_ids(message)
         rev_id = self.top_rev.rev.revision_id or "(NO REVISION ID)"
         if timestamp:
             date_str = format_date(timestamp, timezone or 0, 'original')


Follow ups