refactor: rewrite commit web links

This commit is contained in:
leo 2024-08-13 19:30:10 +08:00
parent 59a7c74fd1
commit abdf9d7e75
No known key found for this signature in database
2 changed files with 16 additions and 21 deletions

View file

@ -91,8 +91,9 @@ namespace SourceGit.ViewModels
public AvaloniaList<Models.CommitLink> WebLinks public AvaloniaList<Models.CommitLink> WebLinks
{ {
get => _repo.TryGetCommitLinks(); get;
} private set;
} = new AvaloniaList<Models.CommitLink>();
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
{ {
@ -102,6 +103,19 @@ namespace SourceGit.ViewModels
public CommitDetail(Repository repo) public CommitDetail(Repository repo)
{ {
_repo = repo; _repo = repo;
foreach (var remote in repo.Remotes)
{
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" });
else if (url.StartsWith("https://gitlab.com/", StringComparison.Ordinal))
WebLinks.Add(new Models.CommitLink() { Name = "GitLab", URLTemplate = $"{url}/-/commit/SOURCEGIT_COMMIT_HASH_CODE" });
else if (url.StartsWith("https://gitee.com/", StringComparison.Ordinal))
WebLinks.Add(new Models.CommitLink() { Name = "Gitee", URLTemplate = $"{url}/commit/SOURCEGIT_COMMIT_HASH_CODE" });
}
}
} }
public void Cleanup() public void Cleanup()

View file

@ -496,25 +496,6 @@ namespace SourceGit.ViewModels
PopupHost.ShowAndStartPopup(new Cleanup(this)); PopupHost.ShowAndStartPopup(new Cleanup(this));
} }
public AvaloniaList<Models.CommitLink> TryGetCommitLinks()
{
var rs = new AvaloniaList<Models.CommitLink>();
foreach (var remote in _remotes)
{
if (remote.TryGetVisitURL(out var url))
{
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
rs.Add(new Models.CommitLink() { Name = "Github", URLTemplate = $"{url}/commit/SOURCEGIT_COMMIT_HASH_CODE" });
else if (url.StartsWith("https://gitlab.com/", StringComparison.Ordinal))
rs.Add(new Models.CommitLink() { Name = "GitLab", URLTemplate = $"{url}/-/commit/SOURCEGIT_COMMIT_HASH_CODE" });
else if (url.StartsWith("https://gitee.com/", StringComparison.Ordinal))
rs.Add(new Models.CommitLink() { Name = "Gitee", URLTemplate = $"{url}/commit/SOURCEGIT_COMMIT_HASH_CODE" });
}
}
return rs;
}
public void ClearHistoriesFilter() public void ClearHistoriesFilter()
{ {
_settings.Filters.Clear(); _settings.Filters.Clear();