mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
refactor: rewrite commit web link
* add support for Bitbucket
This commit is contained in:
parent
48de509c63
commit
bf6ac4d20d
4 changed files with 13 additions and 9 deletions
|
@ -3,6 +3,6 @@
|
||||||
public class CommitLink
|
public class CommitLink
|
||||||
{
|
{
|
||||||
public string Name { get; set; } = null;
|
public string Name { get; set; } = null;
|
||||||
public string URLTemplate { get; set; } = null;
|
public string URLPrefix { get; set; } = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,10 +58,12 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
if (URL.StartsWith("http", StringComparison.Ordinal))
|
if (URL.StartsWith("http", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
if (URL.EndsWith(".git"))
|
// Try to remove the user before host and `.git` extension.
|
||||||
url = URL.Substring(0, URL.Length - 4);
|
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
|
else
|
||||||
url = URL;
|
url = $"{uri.Scheme}://{uri.Host}{uri.LocalPath}";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,11 +109,13 @@ namespace SourceGit.ViewModels
|
||||||
if (remote.TryGetVisitURL(out var url))
|
if (remote.TryGetVisitURL(out var url))
|
||||||
{
|
{
|
||||||
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
|
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))
|
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))
|
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/" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
foreach (var link in links)
|
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 };
|
var item = new MenuItem() { Header = link.Name };
|
||||||
item.Click += (_, ev) =>
|
item.Click += (_, ev) =>
|
||||||
{
|
{
|
||||||
|
@ -66,7 +66,7 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
else if (links.Count == 1)
|
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);
|
Native.OS.OpenBrowser(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue