mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 18:17:53 -06:00
refactor: link platform lists through permalinks
ListSource.browse builds file links with source_permalink, which quotes the path. A list read at no revision still links the repository, and a GitLab list with no path now links its tree instead of a blob URL ending in a slash.
This commit is contained in:
1 parent
d56c3e6e22
commit
f025264f4e
2 files changed
+18
-11
No files matched your search
@@ -693,17 +693,15 @@ class ListSource:
|
||||
end: int | None = None) -> str:
|
||||
"""The page a reader opens: the file, or the tree, at the revision."""
|
||||
path = path or self.path
|
||||
if self.host == "gitlab.com":
|
||||
url = f"https://gitlab.com/{self.owner}/{self.repo}/-/blob/{self.rev}/{path}"
|
||||
anchor = f"#L{start}" + (f"-{end}" if end and end != start else "")
|
||||
else:
|
||||
base = f"https://github.com/{self.owner}/{self.repo}"
|
||||
if not self.rev:
|
||||
return base
|
||||
kind = "blob" if path else "tree"
|
||||
url = f"{base}/{kind}/{self.rev}" + (f"/{path}" if path else "")
|
||||
anchor = f"#L{start}" + (f"-L{end}" if end and end != start else "")
|
||||
return url + (anchor if start else "")
|
||||
repo = upstream.make_repo(self.host, self.owner, self.repo)
|
||||
if repo is None:
|
||||
raise ValueError(f"no forge known for {self.host}")
|
||||
base = f"https://{self.host}/{self.owner}/{self.repo}"
|
||||
if not self.rev:
|
||||
return base
|
||||
if not path:
|
||||
return f"{base}/-/tree/{self.rev}" if repo.family == "gitlab" else f"{base}/tree/{self.rev}"
|
||||
return source_permalink(repo, self.rev, path, start or None, end or None)
|
||||
|
||||
|
||||
def list_source(url: str) -> ListSource | None:
|
||||
|
||||
@@ -214,6 +214,15 @@ class EvidenceLinksItsSource(unittest.TestCase):
|
||||
self.assertIn("gitlab.com/recalbox/recalbox/-/blob/10.1.1/a/b.py#L3",
|
||||
launcher_ref_markdown(source, "a/b.py:3"))
|
||||
|
||||
def test_a_list_link_is_the_source_permalink(self):
|
||||
"""browse() built its own GitHub and GitLab URLs, a space left unquoted."""
|
||||
github = list_source("https://github.com/o/r/blob/v1/dir/a b.cs")
|
||||
self.assertEqual(github.browse(start=3, end=5), "https://github.com/o/r/blob/v1/dir/a%20b.cs#L3-L5")
|
||||
self.assertEqual(list_source("https://codeload.github.com/o/r/tar.gz/v1").browse(),
|
||||
"https://github.com/o/r/tree/v1")
|
||||
gitlab = list_source("https://gitlab.com/o/r/-/raw/v1/es_bios.xml")
|
||||
self.assertEqual(gitlab.browse(start=3, end=5), "https://gitlab.com/o/r/-/blob/v1/es_bios.xml#L3-5")
|
||||
|
||||
|
||||
class EachEntryNamesItsFile(unittest.TestCase):
|
||||
def test_served_held_and_missing(self):
|
||||
|
||||
Reference in new issue
Block a user