From bbfc94d624d7ec2c1d77a64fc2661c77ebc70ca3 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Sun, 10 Nov 2024 04:56:08 +0000 Subject: [PATCH] enhance: several commit links improvements (#672) * Codeberge (https://codeberg.org/) * Gitea (https://gitea.org/) * sourcehut (https://git.sr.ht/) --- src/ViewModels/CommitDetail.cs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index 1600c4cd..f1f39f6f 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -116,13 +116,19 @@ namespace SourceGit.ViewModels if (remote.TryGetVisitURL(out var url)) { if (url.StartsWith("https://github.com/", StringComparison.Ordinal)) - WebLinks.Add(new Models.CommitLink() { Name = "Github", URLPrefix = $"{url}/commit/" }); - else if (url.StartsWith("https://gitlab.com/", StringComparison.Ordinal)) - WebLinks.Add(new Models.CommitLink() { Name = "GitLab", URLPrefix = $"{url}/-/commit/" }); + WebLinks.Add(new Models.CommitLink() { Name = CommitUrlTitle("Github", url), URLPrefix = $"{url}/commit/" }); + else if (url.StartsWith("https://gitlab.", StringComparison.Ordinal)) + WebLinks.Add(new Models.CommitLink() { Name = CommitUrlTitle("GitLab", url), URLPrefix = $"{url}/-/commit/" }); else if (url.StartsWith("https://gitee.com/", StringComparison.Ordinal)) - WebLinks.Add(new Models.CommitLink() { Name = "Gitee", URLPrefix = $"{url}/commit/" }); + WebLinks.Add(new Models.CommitLink() { Name = CommitUrlTitle("Gitee", url), URLPrefix = $"{url}/commit/" }); else if (url.StartsWith("https://bitbucket.org/", StringComparison.Ordinal)) - WebLinks.Add(new Models.CommitLink() { Name = "Bitbucket", URLPrefix = $"{url}/commits/" }); + WebLinks.Add(new Models.CommitLink() { Name = CommitUrlTitle("Bitbucket", url), URLPrefix = $"{url}/commits/" }); + else if (url.StartsWith("https://codeberg.org/", StringComparison.Ordinal)) + WebLinks.Add(new Models.CommitLink() { Name = CommitUrlTitle("Codeberg", url), URLPrefix = $"{url}/commit/" }); + else if (url.StartsWith("https://gitea.org/", StringComparison.Ordinal)) + WebLinks.Add(new Models.CommitLink() { Name = CommitUrlTitle("Gitea", url), URLPrefix = $"{url}/commit/" }); + else if (url.StartsWith("https://git.sr.ht/", StringComparison.Ordinal)) + WebLinks.Add(new Models.CommitLink() { Name = CommitUrlTitle("sourcehut", url), URLPrefix = $"{url}/commit/" }); } } } @@ -639,6 +645,18 @@ namespace SourceGit.ViewModels menu.Items.Add(new MenuItem() { Header = "-" }); } + private string CommitUrlTitle(string provider, string url) + { + try + { + return string.Format("{0} ({1})", provider, string.Join('/', url.Split('/')[3..5])); + } + catch + { + return provider; + } + } + [GeneratedRegex(@"^version https://git-lfs.github.com/spec/v\d+\r?\noid sha256:([0-9a-f]+)\r?\nsize (\d+)[\r\n]*$")] private static partial Regex REG_LFS_FORMAT();