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
=== modified file 'lib/lp/code/model/gitref.py'
--- lib/lp/code/model/gitref.py 2018-11-09 22:06:43 +0000
+++ lib/lp/code/model/gitref.py 2018-12-18 18:00:51 +0000
@@ -686,7 +686,7 @@
686def _fetch_blob_from_github(repository_url, ref_path, filename):686def _fetch_blob_from_github(repository_url, ref_path, filename):
687 repo_path = urlsplit(repository_url).path.strip("/")687 repo_path = urlsplit(repository_url).path.strip("/")
688 if repo_path.endswith(".git"):688 if repo_path.endswith(".git"):
689 repo_path = repo_path[:len(".git")]689 repo_path = repo_path[:-len(".git")]
690 try:690 try:
691 response = urlfetch(691 response = urlfetch(
692 "https://raw.githubusercontent.com/%s/%s/%s" % (692 "https://raw.githubusercontent.com/%s/%s/%s" % (
693693
=== modified file 'lib/lp/code/model/tests/test_gitref.py'
--- lib/lp/code/model/tests/test_gitref.py 2018-11-09 22:06:43 +0000
+++ lib/lp/code/model/tests/test_gitref.py 2018-12-18 18:00:51 +0000
@@ -421,6 +421,16 @@
421 self.assertEqual(b"foo", ref.getBlob("dir/file"))421 self.assertEqual(b"foo", ref.getBlob("dir/file"))
422422
423 @responses.activate423 @responses.activate
424 def test_remote_github_trailing_dot_git(self):
425 ref = self.factory.makeGitRefRemote(
426 repository_url="https://github.com/owner/name.git", path="HEAD")
427 responses.add(
428 "GET",
429 "https://raw.githubusercontent.com/owner/name/HEAD/dir/file",
430 body=b"foo")
431 self.assertEqual(b"foo", ref.getBlob("dir/file"))
432
433 @responses.activate
424 def test_remote_github_404(self):434 def test_remote_github_404(self):
425 ref = self.factory.makeGitRefRemote(435 ref = self.factory.makeGitRefRemote(
426 repository_url="https://github.com/owner/name", path="HEAD")436 repository_url="https://github.com/owner/name", path="HEAD")