launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #28470
[Merge] ~cjwatson/launchpad:gitlab-dash-issues into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:gitlab-dash-issues into launchpad:master.
Commit message:
Handle GitLab URLs ending in "/-/issues"
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1974129 in Launchpad itself: "bugwatch: connection error to gitlab.gnome.org"
https://bugs.launchpad.net/launchpad/+bug/1974129
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/422955
`<repository>/issues` redirects to `<repository>/-/issues`, so people can and do use either form in bug watches.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:gitlab-dash-issues into launchpad:master.
diff --git a/lib/lp/bugs/externalbugtracker/gitlab.py b/lib/lp/bugs/externalbugtracker/gitlab.py
index 444fcb1..9d00095 100644
--- a/lib/lp/bugs/externalbugtracker/gitlab.py
+++ b/lib/lp/bugs/externalbugtracker/gitlab.py
@@ -46,7 +46,12 @@ class GitLab(ExternalBugTracker):
path = path.strip("/")
if not path.endswith("/issues"):
raise BadGitLabURL(baseurl)
- path = "/api/v4/projects/%s" % quote(path[:-len("/issues")], safe="")
+ # GitLab redirects <repository>/issues to <repository>/-/issues, so
+ # people might use either form.
+ base_path = path[:-len("/issues")]
+ if base_path.endswith("/-"):
+ base_path = base_path[:-len("/-")]
+ path = "/api/v4/projects/%s" % quote(base_path, safe="")
baseurl = urlunsplit(("https", host, path, query, fragment))
super().__init__(baseurl)
self.cached_bugs = {}
diff --git a/lib/lp/bugs/externalbugtracker/tests/test_gitlab.py b/lib/lp/bugs/externalbugtracker/tests/test_gitlab.py
index 2ed17bf..391da5b 100644
--- a/lib/lp/bugs/externalbugtracker/tests/test_gitlab.py
+++ b/lib/lp/bugs/externalbugtracker/tests/test_gitlab.py
@@ -70,6 +70,18 @@ class TestGitLab(TestCase):
self.assertRaises(
BadGitLabURL, GitLab, "https://gitlab.com/user/repository")
+ def test_parses_issues_url(self):
+ tracker = GitLab("https://gitlab.com/user/repository/issues")
+ self.assertEqual(
+ "https://gitlab.com/api/v4/projects/user%2Frepository",
+ tracker.baseurl)
+
+ def test_parses_dash_issues_url(self):
+ tracker = GitLab("https://gitlab.com/user/repository/-/issues")
+ self.assertEqual(
+ "https://gitlab.com/api/v4/projects/user%2Frepository",
+ tracker.baseurl)
+
@responses.activate
def test__getPage_authenticated(self):
responses.add(