Rev 3: * Generate --fixes revision properties from lp:xxx references in NEWS. in http://people.canonical.com/~robertc/baz2.0/plugins/commitfromnews/trunk
Robert Collins
robertc at robertcollins.net
Tue Apr 3 08:40:59 UTC 2012
At http://people.canonical.com/~robertc/baz2.0/plugins/commitfromnews/trunk
------------------------------------------------------------
revno: 3 [merge]
revision-id: robertc at robertcollins.net-20120403084041-0jtepr6n82by1k4a
parent: robertc at robertcollins.net-20100227123857-5puwvng9iddlw3ob
parent: jelmer at samba.org-20111208134654-br60kxvylb21xwvo
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Tue 2012-04-03 20:40:41 +1200
message:
* Generate --fixes revision properties from lp:xxx references in NEWS.
(Partial fix for lp:528968) (Jelmer Vernooij)
modified:
NEWS news-20100227062211-t71cc2sjczfyjh9u-1
committemplate.py committemplate.py-20100227062211-t71cc2sjczfyjh9u-2
tests/test_committemplate.py test_committemplate.-20100227062211-t71cc2sjczfyjh9u-3
=== modified file 'NEWS'
--- a/NEWS 2010-02-27 12:38:57 +0000
+++ b/NEWS 2012-04-03 08:40:41 +0000
@@ -12,3 +12,6 @@
NEWS diff.
* Merge messages in the changed-NEWS file case.
+
+* Generate --fixes revision properties from lp:xxx references in NEWS.
+ (Partial fix for lp:528968) (Jelmer Vernooij)
=== modified file 'committemplate.py'
--- a/committemplate.py 2010-02-27 12:38:57 +0000
+++ b/committemplate.py 2011-12-08 13:46:54 +0000
@@ -18,8 +18,11 @@
from bzrlib.lazy_import import lazy_import
lazy_import(globals(), """
-from bzrlib import osutils, patiencediff
+from bzrlib import bugtracker, errors, osutils, patiencediff
""")
+import re
+
+_BUG_MATCH = re.compile(r'lp:(\d+)')
class CommitTemplate(object):
@@ -85,6 +88,16 @@
if tag == 'delete':
continue
new_lines.extend(new[j1:j2])
+ if not self.commit.revprops.get('bugs'):
+ # TODO: Allow the user to configure the bug tracker to use
+ # rather than hardcoding Launchpad.
+ bt = bugtracker.tracker_registry.get('launchpad')
+ bugids = []
+ for line in new_lines:
+ bugids.extend(_BUG_MATCH.findall(line))
+ self.commit.revprops['bugs'] = \
+ bugtracker.encode_fixes_bug_urls(
+ [bt.get_bug_url(bugid) for bugid in bugids])
return self.merge_message(''.join(new_lines))
def merge_message(self, new_message):
=== modified file 'tests/test_committemplate.py'
--- a/tests/test_committemplate.py 2010-02-27 12:17:25 +0000
+++ b/tests/test_committemplate.py 2011-12-08 13:46:54 +0000
@@ -20,9 +20,25 @@
from bzrlib import msgeditor
from bzrlib.tests import TestCaseWithTransport
+INITIAL_NEWS_CONTENT = """----------------------------
+commitfromnews release notes
+----------------------------
+
+NEXT (In development)
+---------------------
+
+IMPROVEMENTS
+~~~~~~~~~~~~
+
+* Created plugin, basic functionality of looking for NEWS and including the
+ NEWS diff.
+"""
+
+
class TestCommitTemplate(TestCaseWithTransport):
def capture_template(self, commit, message):
+ self.commits.append(commit)
self.messages.append(message)
if message is None:
message = 'let this commit succeed I command thee.'
@@ -33,6 +49,7 @@
msgeditor.hooks.install_named_hook('commit_message_template',
self.capture_template, 'commitfromnews test template')
self.messages = []
+ self.commits = []
def test_initial(self):
self.setup_capture()
@@ -50,19 +67,7 @@
self.setup_capture()
builder = self.make_branch_builder('test')
builder.start_series()
- content = """----------------------------
-commitfromnews release notes
-----------------------------
-
-NEXT (In development)
----------------------
-
-IMPROVEMENTS
-~~~~~~~~~~~~
-
-* Created plugin, basic functionality of looking for NEWS and including the
- NEWS diff.
-"""
+ content = INITIAL_NEWS_CONTENT
builder.build_snapshot('BASE-id', None,
[('add', ('', None, 'directory', None)),
('add', ('NEWS', 'foo-id', 'file', content)),
@@ -75,19 +80,7 @@
self.setup_capture()
builder = self.make_branch_builder('test')
builder.start_series()
- orig_content = """----------------------------
-commitfromnews release notes
-----------------------------
-
-NEXT (In development)
----------------------
-
-IMPROVEMENTS
-~~~~~~~~~~~~
-
-* Created plugin, basic functionality of looking for NEWS and including the
- NEWS diff.
-"""
+ orig_content = INITIAL_NEWS_CONTENT
mod_content = """----------------------------
commitfromnews release notes
----------------------------
@@ -117,5 +110,44 @@
builder.finish_series()
self.assertEqual([change_content], self.messages)
+ def test_fix_bug(self):
+ self.setup_capture()
+ builder = self.make_branch_builder('test')
+ builder.start_series()
+ orig_content = INITIAL_NEWS_CONTENT
+ mod_content = """----------------------------
+commitfromnews release notes
+----------------------------
+
+NEXT (In development)
+---------------------
+
+IMPROVEMENTS
+~~~~~~~~~~~~
+
+* Created plugin, basic functionality of looking for NEWS and including the
+ NEWS diff.
+
+* Fixed a horrible bug. (lp:523423)
+
+"""
+ change_content = """
+* Fixed a horrible bug. (lp:523423)
+
+"""
+ builder.build_snapshot('BASE-id', None,
+ [('add', ('', None, 'directory', None)),
+ ('add', ('NEWS', 'foo-id', 'file', orig_content)),
+ ])
+ builder.build_snapshot(None, None,
+ [('modify', ('foo-id', mod_content)),
+ ],
+ message_callback=msgeditor.generate_commit_message_template)
+ builder.finish_series()
+ self.assertEqual([change_content], self.messages)
+ self.assertEqual(1, len(self.commits))
+ self.assertEquals('https://launchpad.net/bugs/523423 fixed',
+ self.commits[0].revprops['bugs'])
+
def _todo_test_passes_messages_through(self):
pass
More information about the bazaar-commits
mailing list