diff --git a/src/Models/CommitLink.cs b/src/Models/CommitLink.cs index 6a421797..955779a8 100644 --- a/src/Models/CommitLink.cs +++ b/src/Models/CommitLink.cs @@ -3,6 +3,6 @@ public class CommitLink { public string Name { get; set; } = null; - public string URLTemplate { get; set; } = null; + public string URLPrefix { get; set; } = null; } } diff --git a/src/Models/Remote.cs b/src/Models/Remote.cs index e068deda..2aa69cb5 100644 --- a/src/Models/Remote.cs +++ b/src/Models/Remote.cs @@ -58,10 +58,12 @@ namespace SourceGit.Models if (URL.StartsWith("http", StringComparison.Ordinal)) { - if (URL.EndsWith(".git")) - url = URL.Substring(0, URL.Length - 4); + // Try to remove the user before host and `.git` extension. + var uri = new Uri(URL.EndsWith(".git", StringComparison.Ordinal) ? URL.Substring(0, URL.Length - 4) : URL); + if (uri.Port != 80 && uri.Port != 443) + url = $"{uri.Scheme}://{uri.Host}:{uri.Port}{uri.LocalPath}"; else - url = URL; + url = $"{uri.Scheme}://{uri.Host}{uri.LocalPath}"; return true; } diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index 2cf549f2..6afbf226 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -109,11 +109,13 @@ namespace SourceGit.ViewModels if (remote.TryGetVisitURL(out var url)) { if (url.StartsWith("https://github.com/", StringComparison.Ordinal)) - WebLinks.Add(new Models.CommitLink() { Name = "Github", URLTemplate = $"{url}/commit/SOURCEGIT_COMMIT_HASH_CODE" }); + 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", URLTemplate = $"{url}/-/commit/SOURCEGIT_COMMIT_HASH_CODE" }); + WebLinks.Add(new Models.CommitLink() { Name = "GitLab", URLPrefix = $"{url}/-/commit/" }); else if (url.StartsWith("https://gitee.com/", StringComparison.Ordinal)) - WebLinks.Add(new Models.CommitLink() { Name = "Gitee", URLTemplate = $"{url}/commit/SOURCEGIT_COMMIT_HASH_CODE" }); + WebLinks.Add(new Models.CommitLink() { Name = "Gitee", URLPrefix = $"{url}/commit/" }); + else if (url.StartsWith("https://bitbucket.org/", StringComparison.Ordinal)) + WebLinks.Add(new Models.CommitLink() { Name = "Bithbucket", URLPrefix = $"{url}/commits/" }); } } } diff --git a/src/Views/CommitBaseInfo.axaml.cs b/src/Views/CommitBaseInfo.axaml.cs index 8c5e3d98..642ae98b 100644 --- a/src/Views/CommitBaseInfo.axaml.cs +++ b/src/Views/CommitBaseInfo.axaml.cs @@ -51,7 +51,7 @@ namespace SourceGit.Views foreach (var link in links) { - var url = link.URLTemplate.Replace("SOURCEGIT_COMMIT_HASH_CODE", detail.Commit.SHA); + var url = $"{link.URLPrefix}{detail.Commit.SHA}"; var item = new MenuItem() { Header = link.Name }; item.Click += (_, ev) => { @@ -66,7 +66,7 @@ namespace SourceGit.Views } else if (links.Count == 1) { - var url = links[0].URLTemplate.Replace("SOURCEGIT_COMMIT_HASH_CODE", detail.Commit.SHA); + var url = $"{links[0].URLPrefix}{detail.Commit.SHA}"; Native.OS.OpenBrowser(url); } }