BuildCommitUrl

This commit is contained in:
M-L-Ml 2025-04-21 19:15:58 +02:00
parent 29d841a3ce
commit bc88612d36

View file

@ -21,7 +21,7 @@ namespace SourceGit.Models
string Name, string Name,
string HostPrefix, string HostPrefix,
Func<string, string> ExtractRepo, Func<string, string> ExtractRepo,
Func<string, string, string> BuildCommitUrl) Func<string, string> BuildCommitUrlPrefix)
{ {
public bool IsMatch(string url) => url.StartsWith(HostPrefix, StringComparison.Ordinal); public bool IsMatch(string url) => url.StartsWith(HostPrefix, StringComparison.Ordinal);
} }
@ -32,7 +32,7 @@ namespace SourceGit.Models
"Github", "Github",
"https://github.com/", "https://github.com/",
url => url.EndsWith(".git") ? url[19..^4] : url[19..], url => url.EndsWith(".git") ? url[19..^4] : url[19..],
(baseUrl, commit) => $"{baseUrl}/commit/{commit}" baseUrl => $"{baseUrl}/commit/"
), ),
new ProviderInfo( new ProviderInfo(
"GitLab", "GitLab",
@ -42,37 +42,37 @@ namespace SourceGit.Models
int idx = trimmed.IndexOf('/') + 1; int idx = trimmed.IndexOf('/') + 1;
return trimmed[idx..]; return trimmed[idx..];
}, },
(baseUrl, commit) => $"{baseUrl}/-/commit/{commit}" baseUrl => $"{baseUrl}/-/commit/"
), ),
new ProviderInfo( new ProviderInfo(
"Gitee", "Gitee",
"https://gitee.com/", "https://gitee.com/",
url => url.EndsWith(".git") ? url[18..^4] : url[18..], url => url.EndsWith(".git") ? url[18..^4] : url[18..],
(baseUrl, commit) => $"{baseUrl}/commit/{commit}" baseUrl => $"{baseUrl}/commit/"
), ),
new ProviderInfo( new ProviderInfo(
"BitBucket", "BitBucket",
"https://bitbucket.org/", "https://bitbucket.org/",
url => url.EndsWith(".git") ? url[22..^4] : url[22..], url => url.EndsWith(".git") ? url[22..^4] : url[22..],
(baseUrl, commit) => $"{baseUrl}/commits/{commit}" baseUrl => $"{baseUrl}/commits/"
), ),
new ProviderInfo( new ProviderInfo(
"Codeberg", "Codeberg",
"https://codeberg.org/", "https://codeberg.org/",
url => url.EndsWith(".git") ? url[21..^4] : url[21..], url => url.EndsWith(".git") ? url[21..^4] : url[21..],
(baseUrl, commit) => $"{baseUrl}/commit/{commit}" baseUrl => $"{baseUrl}/commit/"
), ),
new ProviderInfo( new ProviderInfo(
"Gitea", "Gitea",
"https://gitea.org/", "https://gitea.org/",
url => url.EndsWith(".git") ? url[18..^4] : url[18..], url => url.EndsWith(".git") ? url[18..^4] : url[18..],
(baseUrl, commit) => $"{baseUrl}/commit/{commit}" baseUrl => $"{baseUrl}/commit/"
), ),
new ProviderInfo( new ProviderInfo(
"sourcehut", "sourcehut",
"https://git.sr.ht/", "https://git.sr.ht/",
url => url.EndsWith(".git") ? url[18..^4] : url[18..], url => url.EndsWith(".git") ? url[18..^4] : url[18..],
(baseUrl, commit) => $"{baseUrl}/commit/{commit}" baseUrl => $"{baseUrl}/commit/"
) )
}; };
@ -89,7 +89,7 @@ namespace SourceGit.Models
if (provider.IsMatch(url)) if (provider.IsMatch(url))
{ {
string repoName = provider.ExtractRepo(url); string repoName = provider.ExtractRepo(url);
outs.Add(new CommitLink($"{provider.Name} ({repoName})", provider.BuildCommitUrl(url, ""))); outs.Add(new CommitLink($"{provider.Name} ({repoName})", provider.BuildCommitUrlPrefix(url)));
break; break;
} }
} }