Merge lp:~cjwatson/launchpad/fix-github-blob-dot-git into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18844
Proposed branch: lp:~cjwatson/launchpad/fix-github-blob-dot-git
Merge into: lp:launchpad
Diff against target: 33 lines (+11/-1)
2 files modified
lib/lp/code/model/gitref.py (+1/-1)
lib/lp/code/model/tests/test_gitref.py (+10/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/fix-github-blob-dot-git
Reviewer Review Type Date Requested Status
William Grant code Approve
Tom Wardill (community) Approve
Review via email: mp+361087@code.launchpad.net

Commit message

Fix handling of trailing ".git" when fetching blobs from GitHub.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve
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/code/model/gitref.py'
2--- lib/lp/code/model/gitref.py 2018-11-09 22:06:43 +0000
3+++ lib/lp/code/model/gitref.py 2018-12-18 18:00:51 +0000
4@@ -686,7 +686,7 @@
5 def _fetch_blob_from_github(repository_url, ref_path, filename):
6 repo_path = urlsplit(repository_url).path.strip("/")
7 if repo_path.endswith(".git"):
8- repo_path = repo_path[:len(".git")]
9+ repo_path = repo_path[:-len(".git")]
10 try:
11 response = urlfetch(
12 "https://raw.githubusercontent.com/%s/%s/%s" % (
13
14=== modified file 'lib/lp/code/model/tests/test_gitref.py'
15--- lib/lp/code/model/tests/test_gitref.py 2018-11-09 22:06:43 +0000
16+++ lib/lp/code/model/tests/test_gitref.py 2018-12-18 18:00:51 +0000
17@@ -421,6 +421,16 @@
18 self.assertEqual(b"foo", ref.getBlob("dir/file"))
19
20 @responses.activate
21+ def test_remote_github_trailing_dot_git(self):
22+ ref = self.factory.makeGitRefRemote(
23+ repository_url="https://github.com/owner/name.git", path="HEAD")
24+ responses.add(
25+ "GET",
26+ "https://raw.githubusercontent.com/owner/name/HEAD/dir/file",
27+ body=b"foo")
28+ self.assertEqual(b"foo", ref.getBlob("dir/file"))
29+
30+ @responses.activate
31 def test_remote_github_404(self):
32 ref = self.factory.makeGitRefRemote(
33 repository_url="https://github.com/owner/name", path="HEAD")