Merge ~pieq/bugit/+git/qabro:better-bug-creation-and-error-handling into bugit:master

Proposed by Pierre Equoy
Status: Merged
Approved by: Pierre Equoy
Approved revision: 76f8c97a0c26d3a90553ceceee32f0e18aed751d
Merged at revision: c00dbcfad6a8a8e1305e07b697b4b629fdf0cc42
Proposed branch: ~pieq/bugit/+git/qabro:better-bug-creation-and-error-handling
Merge into: bugit:master
Diff against target: 100 lines (+26/-21)
1 file modified
qabro/bug_assistant.py (+26/-21)
Reviewer Review Type Date Requested Status
Pierre Equoy Approve
Review via email: mp+349044@code.launchpad.net

Description of the change

See commit description for more info.

To test, you can use a small python script:

-----
#!/usr/bin/env python
import qabro

qabro.main()
-----

To trigger an error (and therefore to check the "bug update" feature), try to create an issue in the "qa-candidate" project (it's a test project owned by Jerry) with importance set to "Critical" (only Jerry can set importance, so this should trigger the error).

To post a comment you must log in.
Revision history for this message
Pierre Equoy (pieq) wrote :

Self-approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/qabro/bug_assistant.py b/qabro/bug_assistant.py
2index c2a3927..782b11a 100644
3--- a/qabro/bug_assistant.py
4+++ b/qabro/bug_assistant.py
5@@ -38,6 +38,8 @@ class BugAssistant:
6
7 def __init__(self, bug_report):
8 self.update(bug_report)
9+ # Launchpad bug, in case something is wrong after creating the bug
10+ self.bug = None
11
12 def update(self, bug_report):
13 self.lp_title = bug_report.title
14@@ -93,11 +95,9 @@ class BugAssistant:
15 print('Checking project name...')
16 project = launchpad.projects[self.lp_project]
17 #logging.debug('Project found: {0}'.format(project))
18- except Exception as exception:
19- #logging.error(exception)
20+ except Exception as ex:
21 error_message = ('{} launchpad project not found'
22 .format(self.lp_project))
23- #logging.error(error_message)
24 raise BugAssistantError(error_message)
25
26 series_name = self.lp_series
27@@ -117,31 +117,36 @@ class BugAssistant:
28 try:
29 print('Checking assignee...')
30 assignee = launchpad.people[assignee_name]
31- except Exception as exception:
32- #logging.error(exception)
33+ except Exception as ex:
34 error_message = ('{} launchpad user not found'
35 .format(assignee_name))
36- #logging.error(error_message)
37 raise BugAssistantError(error_message)
38
39- print('Creating Launchpad bug report...')
40 std_info = AttachmentAssistant.get_standard_info()
41 std_info_str = '\n'.join(['{}: {}'.format(elt, std_info[elt])
42 for elt in std_info])
43 description = self.lp_description + "\n\n-----\n\n" + std_info_str
44- bug = launchpad.bugs.createBug(title=self.lp_title,
45- description=description,
46- tags=self.lp_tags.split(),
47- target=project)
48+ if not self.bug:
49+ print('Creating Launchpad bug report...')
50+ self.bug = launchpad.bugs.createBug(title=self.lp_title,
51+ description=description,
52+ tags=self.lp_tags.split(),
53+ target=project)
54+ print('Bug report #{} created.'.format(self.bug.id))
55+ else:
56+ print('Updating Launchpad bug report...')
57+ self.bug.title = self.lp_title
58+ self.bug.description = description
59+ tags = self.lp_tags.split()
60+ target = project
61+ self.bug.lp_save()
62+
63 if series:
64- nomination = bug.addNomination(target=series)
65+ nomination = self.bug.addNomination(target=series)
66 nomination.approve()
67
68- #logging.debug('Bug created: {0}'.format(bug))
69- self.bug = bug
70-
71 # Task configuration
72- task = bug.bug_tasks[0]
73+ task = self.bug.bug_tasks[0]
74 print('Setting status...')
75 task.status = self.lp_status
76 print('Setting importance...')
77@@ -154,18 +159,18 @@ class BugAssistant:
78
79 if ('APPORT_STAGING' in os.environ
80 or os.environ.get('APPORT_LAUNCHPAD_INSTANCE', None) == 'staging'):
81- bug_url = STAGING_WEB_ROOT+'bugs/{}'.format(bug.id)
82+ bug_url = STAGING_WEB_ROOT+'bugs/{}'.format(self.bug.id)
83 else:
84- bug_url = LPNET_WEB_ROOT+'bugs/{}'.format(bug.id)
85+ bug_url = LPNET_WEB_ROOT+'bugs/{}'.format(self.bug.id)
86
87- print('Bug report #{} created.'.format(bug.id))
88+ print('Bug report #{} updated.'.format(self.bug.id))
89
90 print('Uploading bug data...')
91 aa = AttachmentAssistant(self.options)
92 aa.run_attachment_methods()
93- aa.upload_attachments(launchpad, bug.id)
94+ aa.upload_attachments(launchpad, self.bug.id)
95
96- return 'Bug report #{} and it attachments are available at <{}>'.format(bug.id, bug_url)
97+ return 'Bug report #{} and it attachments are available at <{}>'.format(self.bug.id, bug_url)
98
99
100 class BugAssistantError(Exception):

Subscribers

People subscribed via source and target branches

to all changes: