Merge lp:~mabac/svammel/bug-749563-set-severity into lp:svammel

Proposed by Mattias Backman
Status: Merged
Merged at revision: 82
Proposed branch: lp:~mabac/svammel/bug-749563-set-severity
Merge into: lp:svammel
Diff against target: 199 lines (+76/-11)
4 files modified
bug_reporting.py (+15/-10)
config.py (+19/-0)
file-failures.py (+3/-1)
tests/test_fail_filer.py (+39/-0)
To merge this branch: bzr merge lp:~mabac/svammel/bug-749563-set-severity
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Matthias Klose Pending
Review via email: mp+56380@code.launchpad.net

Description of the change

Hi,

This branch adds the feature to set Importance for all newly created bugs.

As a side effect it also adds the --ignore-errors parameter which might be used when targeting series etc in the future.

If --ignore-errors is specified only non-critical errors may be ignored, like setting importance fails. Certain errors like an archive being offline will of course still have to make the script bail.

Thanks,

Mattias

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Hi,

I don't really like globals, as they can cause many problems later, but
they are easy to do here, and given the purpose of this script it likely
won't cause many issues.

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bug_reporting.py'
2--- bug_reporting.py 2011-03-22 10:17:01 +0000
3+++ bug_reporting.py 2011-04-05 14:43:58 +0000
4@@ -10,6 +10,7 @@
5 ###############################################################################
6 from config import (
7 print_message,
8+ continue_on_error,
9 )
10
11
12@@ -20,16 +21,7 @@
13 return project.self_link
14
15
16-def file_bug(package_name, description, title, tags, lp):
17- """ File a bug on the package specified by name.
18-
19- Returns the newly created bug or None if no bug was filed.
20- """
21- project_url = get_project_url(package_name, lp)
22- return file_bug_by_url(project_url, description, title, tags, lp)
23-
24-
25-def file_bug_by_url(target_url, description, title, tags, lp):
26+def file_bug_by_url(target_url, description, title, tags, lp, importance=None):
27 """ File a bug on the bug target specified by target_url.
28
29 Returns the newly created bug or None if no bug was filed.
30@@ -40,12 +32,25 @@
31 tags=tags)
32 if bug is not None:
33 print 'Filed bug %i: %s' % (bug.id, bug.web_link)
34+ if importance is not None:
35+ set_bugtask_importance(bug, importance)
36 else:
37 print "Error: unable to file bug '%s'." % title
38
39 return bug
40
41
42+def set_bugtask_importance(bug, importance):
43+ try:
44+ for bug_task in bug.bug_tasks:
45+ bug_task.importance = importance
46+ bug_task.lp_save()
47+ except:
48+ if continue_on_error():
49+ print "Error: unable to set bug importance to '%s' but will proceed." % importance
50+ else:
51+ raise
52+
53 def bug_already_filed(package_name, lp):
54 """ Check to see if this project already has an active bug."""
55 project_url = get_project_url(package_name, lp)
56
57=== modified file 'config.py'
58--- config.py 2011-03-22 10:17:01 +0000
59+++ config.py 2011-04-05 14:43:58 +0000
60@@ -34,6 +34,7 @@
61 base_api_url = ''
62 lp = None
63 verbose = False
64+ignore_errors = False
65
66
67 def verify_inited():
68@@ -46,6 +47,15 @@
69 verbose = state
70
71
72+def set_ignore_errors(state):
73+ global ignore_errors
74+ ignore_errors = state
75+
76+
77+def continue_on_error():
78+ return ignore_errors
79+
80+
81 def get_service_root():
82 verify_inited()
83 return service_root
84@@ -120,6 +130,15 @@
85 parser.add_argument(
86 '--logfile', required=False,
87 help="Path to file where reported bugs are logged.")
88+ parser.add_argument(
89+ '--importance',
90+ choices=['Unknown', 'Critical', 'High', 'Medium', 'Low',
91+ 'Wishlist', 'Undecided'],
92+ help='If specified, sets the Importance of all created bugs.')
93+ parser.add_argument(
94+ '--ignore-errors', action='store_true', dest='ignoreerrors',
95+ help='Ignore errors that do not prevent proper completion, such as ' \
96+ 'failure to set bug attributes.')
97
98 return parser
99
100
101=== modified file 'file-failures.py'
102--- file-failures.py 2011-03-23 08:25:30 +0000
103+++ file-failures.py 2011-04-05 14:43:58 +0000
104@@ -25,6 +25,7 @@
105 get_args_parser,
106 print_message,
107 set_verbose_messages,
108+ set_ignore_errors,
109 )
110 from build_log import (
111 get_file_contents,
112@@ -47,6 +48,7 @@
113 parser = get_args_parser()
114 args = parser.parse_args()
115 set_verbose_messages(args.verbose)
116+set_ignore_errors(args.ignoreerrors)
117
118 init(args.serviceroot, 'testing', '~/.launchpadlib/cache/')
119
120@@ -102,7 +104,7 @@
121 "Will file bug for %s\n desc: %s\n title: %s\n tags: %s" %
122 (spph.package_name, bug_description[0:220], bug_title, bug_tags))
123 bug = file_bug_by_url(spph.url, bug_description, bug_title,
124- bug_tags, get_launchpad())
125+ bug_tags, get_launchpad(), args.importance)
126 if bug is not None and args.logfile is not None:
127 bug_log.write_entry(
128 LogEntry(spph.package_name, spph.version, fail_platform,
129
130=== modified file 'tests/test_fail_filer.py'
131--- tests/test_fail_filer.py 2011-03-01 11:50:47 +0000
132+++ tests/test_fail_filer.py 2011-04-05 14:43:58 +0000
133@@ -22,6 +22,7 @@
134 )
135 from bug_reporting import (
136 bug_already_filed_by_url,
137+ set_bugtask_importance,
138 # get_project_url,
139 # file_bug,
140 )
141@@ -35,6 +36,7 @@
142 inited,
143 ConfigInitError,
144 LaunchpadError,
145+ set_ignore_errors,
146 )
147
148
149@@ -79,6 +81,23 @@
150
151 class TestFileBug(TestCaseWithFixtures):
152
153+ class MockBug:
154+ def __init__(self):
155+ self.bug_tasks = []
156+ def add_bug_task(self, bug_task):
157+ self.bug_tasks.append(bug_task)
158+
159+ class MockBugTask:
160+ def __init__(self, will_fail_on_save):
161+ self.will_fail_on_save = will_fail_on_save
162+ self.importance = 'Undecided'
163+ self.has_saved = False
164+ def lp_save(self):
165+ if self.will_fail_on_save:
166+ raise Exception()
167+ else:
168+ self.has_saved = True
169+
170 def setUp(self):
171 super(TestFileBug, self).setUp()
172
173@@ -106,6 +125,26 @@
174 self.assertFalse(bug_already_filed_by_url('https://dummy',
175 MockLaunchpad()))
176
177+ def test_set_importance_saves(self):
178+ bug = self.MockBug()
179+ bug_task = self.MockBugTask(False)
180+ bug.add_bug_task(bug_task)
181+ set_bugtask_importance(bug, 'High')
182+ self.assertEquals(True, bug_task.has_saved)
183+
184+ def test_set_importance_can_ignore_errors(self):
185+ set_ignore_errors(True)
186+ bug = self.MockBug()
187+ bug.add_bug_task(self.MockBugTask(True))
188+ set_bugtask_importance(bug, 'High')
189+
190+ def test_set_importance_raises(self):
191+ set_ignore_errors(False)
192+ bug = self.MockBug()
193+ bug.add_bug_task(self.MockBugTask(True))
194+ self.assertRaises(Exception, set_bugtask_importance, bug, 'High')
195+
196+
197 # def test_file_bug(self):
198 # bug = file_bug(self.project_name, self.description, self.title,
199 # self.tags, self.lp)

Subscribers

People subscribed via source and target branches