refactor: rewrite commit web link

* add support for Bitbucket
This commit is contained in:
leo 2024-08-15 10:39:31 +08:00
parent 48de509c63
commit bf6ac4d20d
No known key found for this signature in database
4 changed files with 13 additions and 9 deletions

View file

@ -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;
}