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
=== modified file 'lib/lp/bugs/model/bugwatch.py'
--- lib/lp/bugs/model/bugwatch.py 2016-07-04 17:11:29 +0000
+++ lib/lp/bugs/model/bugwatch.py 2018-11-11 23:14:12 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the1# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
@@ -613,12 +613,20 @@
613613
614 def parseSavaneURL(self, scheme, host, path, query):614 def parseSavaneURL(self, scheme, host, path, query):
615 """Extract Savane base URL and bug ID."""615 """Extract Savane base URL and bug ID."""
616 # Savane bugs URLs are in the form /bugs/?<bug-id>, so we616 # We're only interested in URLs that look like they come from a
617 # exclude any path that isn't '/bugs/'. We also exclude query617 # Savane bugtracker. We currently accept URL paths /bugs/ or
618 # string that have a length of more or less than one, since in618 # /bugs/index.php, and accept query strings that are just the bug ID
619 # such cases we'd be taking a guess at the bug ID, which would619 # or that have an item_id parameter containing the bug ID.
620 # probably be wrong.620 if path not in ('/bugs/', '/bugs/index.php'):
621 if path != '/bugs/' or len(query) != 1:621 return None
622 if len(query) == 1 and query.values()[0] is None:
623 # The query string is just a bare ID.
624 remote_bug = query.keys()[0]
625 elif 'item_id' in query:
626 remote_bug = query['item_id']
627 else:
628 return None
629 if not remote_bug.isdigit():
622 return None630 return None
623631
624 # There's only one global Savannah bugtracker registered with632 # There's only one global Savannah bugtracker registered with
@@ -628,13 +636,6 @@
628 urlsplit(alias)[1] for alias in savannah_tracker.aliases]636 urlsplit(alias)[1] for alias in savannah_tracker.aliases]
629 savannah_hosts.append(urlsplit(savannah_tracker.baseurl)[1])637 savannah_hosts.append(urlsplit(savannah_tracker.baseurl)[1])
630638
631 # The remote bug is actually a key in the query dict rather than
632 # a value, so we simply use the first and only key we come
633 # across as a best-effort guess.
634 remote_bug = query.popitem()[0]
635 if remote_bug is None or not remote_bug.isdigit():
636 return None
637
638 if host in savannah_hosts:639 if host in savannah_hosts:
639 return savannah_tracker.baseurl, remote_bug640 return savannah_tracker.baseurl, remote_bug
640 else:641 else:
641642
=== modified file 'lib/lp/bugs/tests/test_bugwatch.py'
--- lib/lp/bugs/tests/test_bugwatch.py 2018-01-02 10:54:31 +0000
+++ lib/lp/bugs/tests/test_bugwatch.py 2018-11-11 23:14:12 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the1# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Tests for BugWatchSet."""4"""Tests for BugWatchSet."""
@@ -143,6 +143,15 @@
143 'bug_id': '22003',143 'bug_id': '22003',
144 'already_registered': True,144 'already_registered': True,
145 }),145 }),
146 ('SavannahWithParameters', {
147 'bugtracker_type': BugTrackerType.SAVANE,
148 'bug_url': (
149 'http://savannah.gnu.org/bugs/index.php'
150 '?func=detailitem&item_id=22003'),
151 'base_url': 'http://savannah.gnu.org/',
152 'bug_id': '22003',
153 'already_registered': True,
154 }),
146 ('Savane', {155 ('Savane', {
147 'bugtracker_type': BugTrackerType.SAVANE,156 'bugtracker_type': BugTrackerType.SAVANE,
148 'bug_url': 'http://savane.example.com/bugs/?12345',157 'bug_url': 'http://savane.example.com/bugs/?12345',