Merge lp:~cjwatson/launchpad/improve-savane-url-parsing into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18821
Proposed branch: lp:~cjwatson/launchpad/improve-savane-url-parsing
Merge into: lp:launchpad
Diff against target: 76 lines (+25/-15)
2 files modified
lib/lp/bugs/model/bugwatch.py (+15/-14)
lib/lp/bugs/tests/test_bugwatch.py (+10/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/improve-savane-url-parsing
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+358610@code.launchpad.net

Commit message

Parse a few more possible Savane URL formats.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/model/bugwatch.py'
2--- lib/lp/bugs/model/bugwatch.py 2016-07-04 17:11:29 +0000
3+++ lib/lp/bugs/model/bugwatch.py 2018-11-11 23:14:12 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 __metaclass__ = type
10@@ -613,12 +613,20 @@
11
12 def parseSavaneURL(self, scheme, host, path, query):
13 """Extract Savane base URL and bug ID."""
14- # Savane bugs URLs are in the form /bugs/?<bug-id>, so we
15- # exclude any path that isn't '/bugs/'. We also exclude query
16- # string that have a length of more or less than one, since in
17- # such cases we'd be taking a guess at the bug ID, which would
18- # probably be wrong.
19- if path != '/bugs/' or len(query) != 1:
20+ # We're only interested in URLs that look like they come from a
21+ # Savane bugtracker. We currently accept URL paths /bugs/ or
22+ # /bugs/index.php, and accept query strings that are just the bug ID
23+ # or that have an item_id parameter containing the bug ID.
24+ if path not in ('/bugs/', '/bugs/index.php'):
25+ return None
26+ if len(query) == 1 and query.values()[0] is None:
27+ # The query string is just a bare ID.
28+ remote_bug = query.keys()[0]
29+ elif 'item_id' in query:
30+ remote_bug = query['item_id']
31+ else:
32+ return None
33+ if not remote_bug.isdigit():
34 return None
35
36 # There's only one global Savannah bugtracker registered with
37@@ -628,13 +636,6 @@
38 urlsplit(alias)[1] for alias in savannah_tracker.aliases]
39 savannah_hosts.append(urlsplit(savannah_tracker.baseurl)[1])
40
41- # The remote bug is actually a key in the query dict rather than
42- # a value, so we simply use the first and only key we come
43- # across as a best-effort guess.
44- remote_bug = query.popitem()[0]
45- if remote_bug is None or not remote_bug.isdigit():
46- return None
47-
48 if host in savannah_hosts:
49 return savannah_tracker.baseurl, remote_bug
50 else:
51
52=== modified file 'lib/lp/bugs/tests/test_bugwatch.py'
53--- lib/lp/bugs/tests/test_bugwatch.py 2018-01-02 10:54:31 +0000
54+++ lib/lp/bugs/tests/test_bugwatch.py 2018-11-11 23:14:12 +0000
55@@ -1,4 +1,4 @@
56-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
57+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
58 # GNU Affero General Public License version 3 (see the file LICENSE).
59
60 """Tests for BugWatchSet."""
61@@ -143,6 +143,15 @@
62 'bug_id': '22003',
63 'already_registered': True,
64 }),
65+ ('SavannahWithParameters', {
66+ 'bugtracker_type': BugTrackerType.SAVANE,
67+ 'bug_url': (
68+ 'http://savannah.gnu.org/bugs/index.php'
69+ '?func=detailitem&item_id=22003'),
70+ 'base_url': 'http://savannah.gnu.org/',
71+ 'bug_id': '22003',
72+ 'already_registered': True,
73+ }),
74 ('Savane', {
75 'bugtracker_type': BugTrackerType.SAVANE,
76 'bug_url': 'http://savane.example.com/bugs/?12345',