Merge lp:~jelmer/brz/related-bugs into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/related-bugs
Merge into: lp:brz
Diff against target: 236 lines (+57/-25)
8 files modified
breezy/bugtracker.py (+4/-3)
breezy/builtins.py (+16/-9)
breezy/log.py (+9/-4)
breezy/plugins/commitfromnews/committemplate.py (+2/-1)
breezy/tests/blackbox/test_commit.py (+16/-0)
breezy/tests/test_bugtracker.py (+5/-3)
breezy/tests/test_options.py (+3/-3)
breezy/tests/test_revision.py (+2/-2)
To merge this branch: bzr merge lp:~jelmer/brz/related-bugs
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+355893@code.launchpad.net

Commit message

Support --bugs= argument to commit to link related bugs (not necessarily ones that were fixed).

Description of the change

Support --bugs= argument to commit to link related bugs (not necessarily ones that were fixed).

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Hm, seems most useful for general issue trackers rather than bugs specifically, so maybe the name is poor, but the idea makes sense. Could link story from each commit related for instance.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bugtracker.py'
2--- breezy/bugtracker.py 2018-05-14 19:59:18 +0000
3+++ breezy/bugtracker.py 2018-11-13 02:02:02 +0000
4@@ -406,16 +406,17 @@
5
6
7 FIXED = 'fixed'
8+RELATED = 'related'
9
10-ALLOWED_BUG_STATUSES = {FIXED}
11+ALLOWED_BUG_STATUSES = {FIXED, RELATED}
12
13
14 def encode_fixes_bug_urls(bug_urls):
15 """Get the revision property value for a commit that fixes bugs.
16
17- :param bug_urls: An iterable of escaped URLs to bugs. These normally
18+ :param bug_urls: An iterable of (escaped URL, tag) tuples. These normally
19 come from `get_bug_url`.
20 :return: A string that will be set as the 'bugs' property of a revision
21 as part of a commit.
22 """
23- return '\n'.join(('%s %s' % (url, FIXED)) for url in bug_urls)
24+ return '\n'.join(('%s %s' % (url, tag)) for (url, tag) in bug_urls)
25
26=== modified file 'breezy/builtins.py'
27--- breezy/builtins.py 2018-11-04 15:48:54 +0000
28+++ breezy/builtins.py 2018-11-13 02:02:02 +0000
29@@ -3518,6 +3518,8 @@
30 Option('commit-time', type=text_type,
31 help="Manually set a commit time using commit date "
32 "format, e.g. '2009-10-10 08:00:00 +0100'."),
33+ ListOption('bugs', type=text_type,
34+ help="Link to a related bug. (see \"brz help bugs\")."),
35 ListOption('fixes', type=text_type,
36 help="Mark a bug as being fixed by this revision "
37 "(see \"brz help bugs\")."),
38@@ -3540,11 +3542,11 @@
39 ]
40 aliases = ['ci', 'checkin']
41
42- def _iter_bug_fix_urls(self, fixes, branch):
43+ def _iter_bug_urls(self, bugs, branch, status):
44 default_bugtracker = None
45 # Configure the properties for bug fixing attributes.
46- for fixed_bug in fixes:
47- tokens = fixed_bug.split(':')
48+ for bug in bugs:
49+ tokens = bug.split(':')
50 if len(tokens) == 1:
51 if default_bugtracker is None:
52 branch_config = branch.get_config_stack()
53@@ -3556,29 +3558,30 @@
54 "'tracker:id' or specify a default bug tracker "
55 "using the `bugtracker` option.\nSee "
56 "\"brz help bugs\" for more information on this "
57- "feature. Commit refused.") % fixed_bug)
58+ "feature. Commit refused.") % bug)
59 tag = default_bugtracker
60 bug_id = tokens[0]
61 elif len(tokens) != 2:
62 raise errors.BzrCommandError(gettext(
63 "Invalid bug %s. Must be in the form of 'tracker:id'. "
64 "See \"brz help bugs\" for more information on this "
65- "feature.\nCommit refused.") % fixed_bug)
66+ "feature.\nCommit refused.") % bug)
67 else:
68 tag, bug_id = tokens
69 try:
70- yield bugtracker.get_bug_url(tag, branch, bug_id)
71+ yield bugtracker.get_bug_url(tag, branch, bug_id), status
72 except bugtracker.UnknownBugTrackerAbbreviation:
73 raise errors.BzrCommandError(gettext(
74- 'Unrecognized bug %s. Commit refused.') % fixed_bug)
75+ 'Unrecognized bug %s. Commit refused.') % bug)
76 except bugtracker.MalformedBugIdentifier as e:
77 raise errors.BzrCommandError(gettext(
78 u"%s\nCommit refused.") % (e,))
79
80 def run(self, message=None, file=None, verbose=False, selected_list=None,
81- unchanged=False, strict=False, local=False, fixes=None,
82+ unchanged=False, strict=False, local=False, fixes=None, bugs=None,
83 author=None, show_diff=False, exclude=None, commit_time=None,
84 lossy=False):
85+ import itertools
86 from .commit import (
87 PointlessCommit,
88 )
89@@ -3612,8 +3615,12 @@
90
91 if fixes is None:
92 fixes = []
93+ if bugs is None:
94+ bugs = []
95 bug_property = bugtracker.encode_fixes_bug_urls(
96- self._iter_bug_fix_urls(fixes, tree.branch))
97+ itertools.chain(
98+ self._iter_bug_urls(bugs, tree.branch, bugtracker.RELATED),
99+ self._iter_bug_urls(fixes, tree.branch, bugtracker.FIXED)))
100 if bug_property:
101 properties[u'bugs'] = bug_property
102
103
104=== modified file 'breezy/log.py'
105--- breezy/log.py 2018-08-15 18:44:16 +0000
106+++ breezy/log.py 2018-11-13 02:02:02 +0000
107@@ -2140,16 +2140,21 @@
108
109 # Use the properties handlers to print out bug information if available
110 def _bugs_properties_handler(revision):
111+ ret = {}
112 if 'bugs' in revision.properties:
113 bug_lines = revision.properties['bugs'].split('\n')
114 bug_rows = [line.split(' ', 1) for line in bug_lines]
115 fixed_bug_urls = [row[0] for row in bug_rows if
116 len(row) > 1 and row[1] == 'fixed']
117-
118+ related_bug_urls = [row[0] for row in bug_rows if
119+ len(row) > 1 and row[1] == 'related']
120 if fixed_bug_urls:
121- return {ngettext('fixes bug', 'fixes bugs', len(fixed_bug_urls)):\
122- ' '.join(fixed_bug_urls)}
123- return {}
124+ ret[ngettext('fixes bug', 'fixes bugs', len(fixed_bug_urls))] = (
125+ ' '.join(fixed_bug_urls))
126+ if related_bug_urls:
127+ ret[ngettext('related bug', 'related bugs', len(related_bug_urls))] = (
128+ ' '.join(related_bug_urls))
129+ return ret
130
131 properties_handler_registry.register('bugs_properties_handler',
132 _bugs_properties_handler)
133
134=== modified file 'breezy/plugins/commitfromnews/committemplate.py'
135--- breezy/plugins/commitfromnews/committemplate.py 2018-07-14 19:18:18 +0000
136+++ breezy/plugins/commitfromnews/committemplate.py 2018-11-13 02:02:02 +0000
137@@ -96,7 +96,8 @@
138 bugids.extend(_BUG_MATCH.findall(line))
139 self.commit.revprops['bugs'] = \
140 bugtracker.encode_fixes_bug_urls(
141- [bt.get_bug_url(bugid) for bugid in bugids])
142+ [(bt.get_bug_url(bugid), bugtracker.FIXED)
143+ for bugid in bugids])
144 return self.merge_message(''.join(new_lines))
145
146 def merge_message(self, new_message):
147
148=== modified file 'breezy/tests/blackbox/test_commit.py'
149--- breezy/tests/blackbox/test_commit.py 2018-08-13 01:38:21 +0000
150+++ breezy/tests/blackbox/test_commit.py 2018-11-13 02:02:02 +0000
151@@ -568,6 +568,22 @@
152 del properties['branch-nick']
153 self.assertFalse('bugs' in properties)
154
155+ def test_bugs_sets_property(self):
156+ """commit --bugs=lp:234 sets the lp:234 revprop to 'related'."""
157+ tree = self.make_branch_and_tree('tree')
158+ self.build_tree(['tree/hello.txt'])
159+ tree.add('hello.txt')
160+ self.run_bzr('commit -m hello --bugs=lp:234 tree/hello.txt')
161+
162+ # Get the revision properties, ignoring the branch-nick property, which
163+ # we don't care about for this test.
164+ last_rev = tree.branch.repository.get_revision(tree.last_revision())
165+ properties = dict(last_rev.properties)
166+ del properties[u'branch-nick']
167+
168+ self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 related'},
169+ properties)
170+
171 def test_fixes_bug_sets_property(self):
172 """commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
173 tree = self.make_branch_and_tree('tree')
174
175=== modified file 'breezy/tests/test_bugtracker.py'
176--- breezy/tests/test_bugtracker.py 2018-05-14 19:59:18 +0000
177+++ breezy/tests/test_bugtracker.py 2018-11-13 02:02:02 +0000
178@@ -324,7 +324,8 @@
179 def test_encoding_one(self):
180 self.assertEqual(
181 'http://example.com/bugs/1 fixed',
182- bugtracker.encode_fixes_bug_urls(['http://example.com/bugs/1']))
183+ bugtracker.encode_fixes_bug_urls(
184+ [('http://example.com/bugs/1', 'fixed')]))
185
186 def test_encoding_zero(self):
187 self.assertEqual('', bugtracker.encode_fixes_bug_urls([]))
188@@ -332,6 +333,7 @@
189 def test_encoding_two(self):
190 self.assertEqual(
191 'http://example.com/bugs/1 fixed\n'
192- 'http://example.com/bugs/2 fixed',
193+ 'http://example.com/bugs/2 related',
194 bugtracker.encode_fixes_bug_urls(
195- ['http://example.com/bugs/1', 'http://example.com/bugs/2']))
196+ [('http://example.com/bugs/1', 'fixed'),
197+ ('http://example.com/bugs/2', 'related')]))
198
199=== modified file 'breezy/tests/test_options.py'
200--- breezy/tests/test_options.py 2018-08-05 20:13:41 +0000
201+++ breezy/tests/test_options.py 2018-11-13 02:02:02 +0000
202@@ -44,16 +44,16 @@
203 # to cmd_commit, when they are meant to be about option parsing in
204 # general.
205 self.assertEqual(
206- ([], {'author': [], 'exclude': [], 'fixes': [], 'help': True}),
207+ ([], {'author': [], 'exclude': [], 'fixes': [], 'help': True, 'bugs': []}),
208 parse_args(cmd_commit(), ['--help']))
209 self.assertEqual(
210- ([], {'author': [], 'exclude': [], 'fixes': [], 'message': 'biter'}),
211+ ([], {'author': [], 'exclude': [], 'fixes': [], 'message': 'biter', 'bugs': []}),
212 parse_args(cmd_commit(), ['--message=biter']))
213
214 def test_no_more_opts(self):
215 """Terminated options"""
216 self.assertEqual(
217- (['-file-with-dashes'], {'author': [], 'exclude': [], 'fixes': []}),
218+ (['-file-with-dashes'], {'author': [], 'exclude': [], 'fixes': [], 'bugs': []}),
219 parse_args(cmd_commit(), ['--', '-file-with-dashes']))
220
221 def test_option_help(self):
222
223=== modified file 'breezy/tests/test_revision.py'
224--- breezy/tests/test_revision.py 2018-07-07 19:27:38 +0000
225+++ breezy/tests/test_revision.py 2018-11-13 02:02:02 +0000
226@@ -230,8 +230,8 @@
227 r = revision.Revision(
228 '1', properties={
229 u'bugs': bugtracker.encode_fixes_bug_urls(
230- ['http://example.com/bugs/1',
231- 'http://launchpad.net/bugs/1234'])})
232+ [('http://example.com/bugs/1', 'fixed'),
233+ ('http://launchpad.net/bugs/1234', 'fixed')])})
234 self.assertEqual(
235 [('http://example.com/bugs/1', bugtracker.FIXED),
236 ('http://launchpad.net/bugs/1234', bugtracker.FIXED)],

Subscribers

People subscribed via source and target branches