Merge lp:~jelmer/bzr-commitfromnews/extractbugnumbers into lp:bzr-commitfromnews

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 3
Proposed branch: lp:~jelmer/bzr-commitfromnews/extractbugnumbers
Merge into: lp:bzr-commitfromnews
Diff against target: 158 lines (+72/-27)
2 files modified
committemplate.py (+14/-1)
tests/test_committemplate.py (+58/-26)
To merge this branch: bzr merge lp:~jelmer/bzr-commitfromnews/extractbugnumbers
Reviewer Review Type Date Requested Status
Robert Collins Pending
Review via email: mp+84953@code.launchpad.net

This proposal supersedes a proposal from 2010-03-30.

Description of the change

Initial work on setting revision properties based on information in NEWS.

Now updated to use "lp:BUGNO" rather than "#BUGNO"

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote : Posted in a previous version of this proposal

 review: needsfixing

This is looking pretty good. Uhm, I don't like #1234 being picked up -
lets look for lp:1234 - that way we don't have any confusion about what
bug tracker. And yes, I think that that will matter a great deal.

You can introspect bzr's bugs module to get a list of prefixes that can
be looked for sensibly, pretty easily.

Cheers,
Rob

review: Needs Fixing
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Updated. This now uses lp:1234 to talk about Launchpad bug numbers. It wasn't quite as easy to handle other bug trackers too, so I've kept it Launchpad-specific for now, but adding support for the other bug trackers should be possible without changing the behaviour for lp-specific bugs.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'committemplate.py'
2--- committemplate.py 2010-02-27 12:38:57 +0000
3+++ committemplate.py 2011-12-08 13:57:23 +0000
4@@ -18,8 +18,11 @@
5
6 from bzrlib.lazy_import import lazy_import
7 lazy_import(globals(), """
8-from bzrlib import osutils, patiencediff
9+from bzrlib import bugtracker, errors, osutils, patiencediff
10 """)
11+import re
12+
13+_BUG_MATCH = re.compile(r'lp:(\d+)')
14
15 class CommitTemplate(object):
16
17@@ -85,6 +88,16 @@
18 if tag == 'delete':
19 continue
20 new_lines.extend(new[j1:j2])
21+ if not self.commit.revprops.get('bugs'):
22+ # TODO: Allow the user to configure the bug tracker to use
23+ # rather than hardcoding Launchpad.
24+ bt = bugtracker.tracker_registry.get('launchpad')
25+ bugids = []
26+ for line in new_lines:
27+ bugids.extend(_BUG_MATCH.findall(line))
28+ self.commit.revprops['bugs'] = \
29+ bugtracker.encode_fixes_bug_urls(
30+ [bt.get_bug_url(bugid) for bugid in bugids])
31 return self.merge_message(''.join(new_lines))
32
33 def merge_message(self, new_message):
34
35=== modified file 'tests/test_committemplate.py'
36--- tests/test_committemplate.py 2010-02-27 12:17:25 +0000
37+++ tests/test_committemplate.py 2011-12-08 13:57:23 +0000
38@@ -20,9 +20,25 @@
39 from bzrlib import msgeditor
40 from bzrlib.tests import TestCaseWithTransport
41
42+INITIAL_NEWS_CONTENT = """----------------------------
43+commitfromnews release notes
44+----------------------------
45+
46+NEXT (In development)
47+---------------------
48+
49+IMPROVEMENTS
50+~~~~~~~~~~~~
51+
52+* Created plugin, basic functionality of looking for NEWS and including the
53+ NEWS diff.
54+"""
55+
56+
57 class TestCommitTemplate(TestCaseWithTransport):
58
59 def capture_template(self, commit, message):
60+ self.commits.append(commit)
61 self.messages.append(message)
62 if message is None:
63 message = 'let this commit succeed I command thee.'
64@@ -33,6 +49,7 @@
65 msgeditor.hooks.install_named_hook('commit_message_template',
66 self.capture_template, 'commitfromnews test template')
67 self.messages = []
68+ self.commits = []
69
70 def test_initial(self):
71 self.setup_capture()
72@@ -50,19 +67,7 @@
73 self.setup_capture()
74 builder = self.make_branch_builder('test')
75 builder.start_series()
76- content = """----------------------------
77-commitfromnews release notes
78-----------------------------
79-
80-NEXT (In development)
81----------------------
82-
83-IMPROVEMENTS
84-~~~~~~~~~~~~
85-
86-* Created plugin, basic functionality of looking for NEWS and including the
87- NEWS diff.
88-"""
89+ content = INITIAL_NEWS_CONTENT
90 builder.build_snapshot('BASE-id', None,
91 [('add', ('', None, 'directory', None)),
92 ('add', ('NEWS', 'foo-id', 'file', content)),
93@@ -75,19 +80,7 @@
94 self.setup_capture()
95 builder = self.make_branch_builder('test')
96 builder.start_series()
97- orig_content = """----------------------------
98-commitfromnews release notes
99-----------------------------
100-
101-NEXT (In development)
102----------------------
103-
104-IMPROVEMENTS
105-~~~~~~~~~~~~
106-
107-* Created plugin, basic functionality of looking for NEWS and including the
108- NEWS diff.
109-"""
110+ orig_content = INITIAL_NEWS_CONTENT
111 mod_content = """----------------------------
112 commitfromnews release notes
113 ----------------------------
114@@ -117,5 +110,44 @@
115 builder.finish_series()
116 self.assertEqual([change_content], self.messages)
117
118+ def test_fix_bug(self):
119+ self.setup_capture()
120+ builder = self.make_branch_builder('test')
121+ builder.start_series()
122+ orig_content = INITIAL_NEWS_CONTENT
123+ mod_content = """----------------------------
124+commitfromnews release notes
125+----------------------------
126+
127+NEXT (In development)
128+---------------------
129+
130+IMPROVEMENTS
131+~~~~~~~~~~~~
132+
133+* Created plugin, basic functionality of looking for NEWS and including the
134+ NEWS diff.
135+
136+* Fixed a horrible bug. (lp:523423)
137+
138+"""
139+ change_content = """
140+* Fixed a horrible bug. (lp:523423)
141+
142+"""
143+ builder.build_snapshot('BASE-id', None,
144+ [('add', ('', None, 'directory', None)),
145+ ('add', ('NEWS', 'foo-id', 'file', orig_content)),
146+ ])
147+ builder.build_snapshot(None, None,
148+ [('modify', ('foo-id', mod_content)),
149+ ],
150+ message_callback=msgeditor.generate_commit_message_template)
151+ builder.finish_series()
152+ self.assertEqual([change_content], self.messages)
153+ self.assertEqual(1, len(self.commits))
154+ self.assertEquals('https://launchpad.net/bugs/523423 fixed',
155+ self.commits[0].revprops['bugs'])
156+
157 def _todo_test_passes_messages_through(self):
158 pass

Subscribers

People subscribed via source and target branches