Skip to content

Commit dcc9a8f

Browse files
fix: generalize getGithubBaseUrl to support any github-compatible forge (#381)
* fix: generalize getGithubBaseUrl to support any git forge The original implementation only accepted github.com URLs. This change generalizes it to accept any HTTPS or SSH git remote: - https://host/org/repo[.git] (GitHub, GitHub Enterprise, Codeberg, Gitea) - git@host:org/repo.git (any SSH remote) This fixes srcUri.github failures for: - GitHub Enterprise (e.g., github.jpl.nasa.gov) - Codeberg/Forgejo/Gitea (e.g., codeberg.org) Note: Source links use GitHub's /blob/COMMIT/path convention. For non-GitHub forges (Codeberg uses /src/commit/), use DOCGEN_SRC=file. * Apply suggestions from code review Co-authored-by: Henrik Böving <hargonix@gmail.com> --------- Co-authored-by: Henrik Böving <hargonix@gmail.com>
1 parent 2c96309 commit dcc9a8f

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

lakefile.lean

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,34 @@ def getProjectCommit (directory : System.FilePath := "." ) : IO String := do
7676
def filteredPath (path : FilePath) : List String := path.components.filter (· != ".")
7777

7878
/--
79-
Turns a Github git remote URL into an HTTPS Github URL.
80-
Three link types from git supported:
79+
Turns a git remote URL into an HTTPS base URL for source linking.
80+
Supported link types:
8181
- https://github.com/org/repo
8282
- https://github.com/org/repo.git
8383
- git@github.com:org/repo.git
84+
- https://github.example.com/org/repo (GitHub Enterprise)
85+
- https://codeberg.org/org/repo.git (Codeberg/Forgejo/Gitea)
86+
- git@host:org/repo.git (any SSH remote)
87+
88+
Note: Source links use GitHub's `/blob/COMMIT/path` convention.
89+
This is correct for GitHub and GitHub Enterprise. For Codeberg/Forgejo/Gitea
90+
(which use `/src/commit/COMMIT/path`), the source links will not resolve.
91+
Use `DOCGEN_SRC=file` as a workaround for non-GitHub hosts.
8492
-/
8593
def getGithubBaseUrl (url : String) : Option String :=
86-
if url.startsWith "git@github.com:" && url.endsWith ".git" then
87-
let url := url.drop "git@github.com:".length
88-
let url := url.dropEnd ".git".length
89-
.some s!"https://github.com/{url}"
90-
else if url.startsWith "https://github.com/" then
91-
if url.endsWith ".git" then
92-
.some <| url.dropEnd ".git".length |>.copy
93-
else
94-
.some url
94+
-- git@host:org/repo.git → https://host/org/repo
95+
if url.startsWith "git@" && url.endsWith ".git" then
96+
let rest := url.drop "git@".length |>.dropEnd ".git".length |>.toString
97+
match rest.splitOn ":" with
98+
| [host, path] => some s!"https://{host}/{path}"
99+
| _ => none
100+
-- https://host/org/repo[.git]
101+
else if url.startsWith "https://" then
102+
let stripped := if url.endsWith ".git" then url.dropEnd ".git".length |>.copy else url
103+
-- Verify at least host/org/repo structure
104+
let afterScheme := stripped.drop "https://".length |>.toString
105+
let parts := afterScheme.splitOn "/"
106+
if parts.length >= 3 then some stripped else none
95107
else
96108
.none
97109

0 commit comments

Comments
 (0)