Merge lp:~jpds/ubuntu-bots/bugs-via-launchpad-api into lp:~tsimpson/ubuntu-bots/tweak

Proposed by Jonathan Davies on 2010-01-24
Status: Rejected
Rejected by: Terence Simpson on 2012-01-28
Proposed branch: lp:~jpds/ubuntu-bots/bugs-via-launchpad-api
Merge into: lp:~tsimpson/ubuntu-bots/tweak
Diff against target: 164 lines (+63/-62)
1 file modified
Bugtracker/plugin.py (+63/-62)
To merge this branch: bzr merge lp:~jpds/ubuntu-bots/bugs-via-launchpad-api
Reviewer Review Type Date Requested Status
Terence Simpson belated 2010-01-24 Disapprove on 2012-01-28
Review via email: mp+17957@code.launchpad.net
To post a comment you must log in.
Jonathan Davies (jpds) wrote :

Added Launchpad API support to Bugtracker.

155. By Jonathan Davies on 2010-01-24

Removed old Launchpad bug snarfing code.

156. By Jonathan Davies on 2010-01-24

Removed debug code.

157. By Jonathan Davies on 2010-01-24

Allow reading data from bug 1 on Launchpad (this is cached).

158. By Jonathan Davies on 2010-01-24

Read task data of a bug from the last task.

159. By Jonathan Davies on 2010-01-24

Really catch private bugs.

160. By Jonathan Davies on 2010-01-24

Catch bugs with more than one task and report the number of tasks.

161. By Jonathan Davies on 2010-01-24

Improved wording of more projects reply.

162. By Jonathan Davies on 2010-01-24

Display how many users a bug affects.

163. By Jonathan Davies on 2010-01-24

Report how many duplicates a bug report has.

164. By Jonathan Davies on 2010-01-24

Added a : here.

165. By Jonathan Davies on 2010-02-04

Bugtracker/plugin.py: Don't import commands - not used.

166. By Jonathan Davies on 2010-02-05

Fall back to auth'ed API login if login_anonymously is not available.

167. By Jonathan Davies on 2010-02-05

Catch AttributeError instead.

168. By Jonathan Davies on 2010-03-30

Display bug heat stuff.

Terence Simpson (tsimpson) wrote :

I'm marking as rejected only because the original feature is now already implemented and so there's no need to attempt a merge.

review: Disapprove (belated)

Unmerged revisions

168. By Jonathan Davies on 2010-03-30

Display bug heat stuff.

167. By Jonathan Davies on 2010-02-05

Catch AttributeError instead.

166. By Jonathan Davies on 2010-02-05

Fall back to auth'ed API login if login_anonymously is not available.

165. By Jonathan Davies on 2010-02-04

Bugtracker/plugin.py: Don't import commands - not used.

164. By Jonathan Davies on 2010-01-24

Added a : here.

163. By Jonathan Davies on 2010-01-24

Report how many duplicates a bug report has.

162. By Jonathan Davies on 2010-01-24

Display how many users a bug affects.

161. By Jonathan Davies on 2010-01-24

Improved wording of more projects reply.

160. By Jonathan Davies on 2010-01-24

Catch bugs with more than one task and report the number of tasks.

159. By Jonathan Davies on 2010-01-24

Really catch private bugs.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Bugtracker/plugin.py'
2--- Bugtracker/plugin.py 2009-11-30 19:04:54 +0000
3+++ Bugtracker/plugin.py 2010-03-30 21:47:24 +0000
4@@ -1,5 +1,6 @@
5 ###
6 # Copyright (c) 2005-2007 Dennis Kaarsemaker
7+# Copyright (C) 2010 Jonathan Davies
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of version 2 of the GNU General Public License as
11@@ -21,12 +22,23 @@
12 import supybot.registry as registry
13 import supybot.schedule as schedule
14
15-import re, os, time, imaplib, commands
16+import re, os, time, imaplib
17 import xml.dom.minidom as minidom
18 from htmlentitydefs import entitydefs as entities
19 import email.FeedParser
20 import SOAPpy
21
22+# Launchpad bindings.
23+from launchpadlib.launchpad import Launchpad
24+cachedir = os.path.expanduser("~/.launchpadlib/cache/")
25+
26+try:
27+ launchpad = Launchpad.login_anonymously('Supybot: Bugtracker plugin', 'edge',
28+ cachedir)
29+except AttributeError:
30+ launchpad = Launchpad.login_with('Supybot: Bugtracker plugin', 'edge',
31+ cachedir)
32+
33 bad_words = ["fuck","fuk","fucking","fuking","fukin","fuckin","fucked","fuked","fucker","shit","cunt","bastard","nazi","nigger","nigga","cock","bitches","bitch"]
34
35 def makeClean(s):
36@@ -372,9 +384,6 @@
37 else:
38 for bugid in bugids:
39 bugid = int(bugid)
40- if bugid == 1 and tracker == self.db["lp"]:
41- irc.reply("https://bugs.launchpad.net/ubuntu/+bug/1 (Not reporting large bug)")
42- continue
43 try:
44 report = self.get_bug(msg.args[0],tracker,bugid,self.registryValue('showassignee', msg.args[0]))
45 except BugNotFoundError:
46@@ -582,68 +591,60 @@
47 return [(id, component, title, severity, status, assignee, "%s/show_bug.cgi?id=%d" % (self.url, id))]
48
49 class Launchpad(IBugtracker):
50- def _parse(self, task):
51- parser = email.FeedParser.FeedParser()
52- parser.feed(task)
53- return parser.close()
54- def _sort(self, task1, task2):
55- # Status sort:
56- try:
57- statuses = ['Rejected', 'Fix Released', 'Fix Committed', 'Unconfirmed','Needs Info','Confirmed','In Progress']
58- severities = ['Undecided', 'Wishlist', 'Minor', 'Low', 'Normal', 'Medium', 'Major', 'High', 'Critical']
59- if task1['status'] not in statuses and task2['status'] in statuses: return -1
60- if task1['status'] in statuses and task2['status'] not in statuses: return 1
61- if task1['importance'] not in severities and task2['importance'] in severities: return -1
62- if task1['importance'] in severities and task2['importance'] not in severities: return 1
63- if not (task1['status'] == task2['status']):
64- if statuses.index(task1['status']) < statuses.index(task2['status']):
65- return -1
66- return 1
67- if not (task1['importance'] == task2['importance']):
68- if severities.index(task1['importance']) < severities.index(task2['importance']):
69- return -1
70- return 1
71- except: # Launchpad changed again?
72- return 0
73- return 0
74 def get_bug(self, id):
75 try:
76-# print("%s/bugs/%d/+text" % (self.url,id))
77- bugdata = utils.web.getUrl("%s/bugs/%d/+text" % (self.url,id))
78- except Exception, e:
79- if '404' in str(e):
80- raise BugNotFoundError
81- s = 'Could not parse data returned by %s: %s (%s/bugs/%d)' % (self.description, e, self.url, id)
82- raise BugtrackerError, s
83- summary = {}
84- # Trap private bugs
85- if "<!-- 4a. didn't try to log in last time: -->" in bugdata:
86- raise BugtrackerError, "This bug is private"
87+ #print "Looking up bug #%s..." % id
88+ bug_data = launchpad.bugs[int(id)]
89+ except KeyError:
90+ raise BugtrackerError, "Bug #%s not found." % id
91+ except:
92+ print Exception.message
93+
94 try:
95- # Split bug data into separate pieces (bug data, task data)
96- data = bugdata.split('\n\n')
97- bugdata = data[0]
98- taskdata = data[1:]
99- parser = email.FeedParser.FeedParser()
100- parser.feed(bugdata)
101- bugdata = parser.close()
102- taskdata = map(self._parse, taskdata)
103- taskdata.sort(self._sort)
104- taskdata = taskdata[-1]
105-
106- except Exception, e:
107- s = 'Could not parse data returned by %s: %s (%s/bugs/%d)' % (self.description, e, self.url, id)
108- raise BugtrackerError, s
109+ bug_data.private
110+ except:
111+ raise BugtrackerError, "Bug #%s is private." % id
112+
113+ bug_title = bug_data.title
114+ people_affected = bug_data.users_affected_count_with_dupes
115+ bug_tasks_number = len(bug_data.bug_tasks) - 1
116+ # Read task data from last task.
117+ bug_task = list(bug_data.bug_tasks)[bug_tasks_number]
118+ bug_project = bug_task.bug_target_name
119+ bug_importance = bug_task.importance
120+ bug_status = bug_task.status
121+ bug_assignee = ""
122+ bug_duplicates = len(bug_data.duplicates)
123+ bug_heat = bug_data.heat
124+
125+ if bug_task.assignee:
126+ bug_assignee = bug_task.assignee.name
127+
128+ if bug_tasks_number > 0:
129+ if bug_tasks_number == 1:
130+ bug_project += " (and %d other project)" % bug_tasks_number
131+ else:
132+ bug_project += " (and %d other projects)" % bug_tasks_number
133+
134 # Try and find duplicates
135- t = taskdata['task']
136- if '(' in t:
137- t = t[:t.rfind('(') -1]
138- if bugdata['duplicate-of']:
139- dupbug = self.get_bug(int(bugdata['duplicate-of']))
140- return [(id, t, bugdata['title'] + (' (dup-of: %d)' % dupbug[0][0]), taskdata['importance'],
141- taskdata['status'], taskdata['assignee'], "%s/bugs/%s" % (self.url, id))] + dupbug
142- return [(id, t, bugdata['title'], taskdata['importance'],
143- taskdata['status'], taskdata['assignee'], "%s/bugs/%s" % (self.url, id))]
144+ if bug_data.duplicate_of is not None:
145+ dup_bug = launchpad.bugs[id].duplicate_of
146+ return [(id, bug_project,
147+ bug_title + (' (dup-of: %d)' % dup_bug.id), bug_importance,
148+ bug_status, bug_assignee,
149+ "%s/bugs/%s" % (self.url, id))] + self.get_bug(dup_bug.id)
150+
151+ if people_affected > 0:
152+ bug_title += " (affects: %d)" % people_affected
153+
154+ if bug_duplicates > 0:
155+ bug_title += " (dups: %d)" % bug_duplicates
156+
157+ if bug_heat != 0:
158+ bug_title += " (heat: %d)" % bug_heat
159+
160+ return [(id, bug_project, bug_title, bug_importance, bug_status,
161+ bug_assignee, "%s/bugs/%s" % (self.url, id))]
162
163 # <rant>
164 # Debbugs sucks donkeyballs

Subscribers

People subscribed via source and target branches