mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24:59 +00:00
feature: supports visit remote url in browser
This commit is contained in:
parent
3afb134037
commit
ad2fc68c6b
6 changed files with 58 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
|
@ -11,6 +12,9 @@ namespace SourceGit.Models
|
|||
[GeneratedRegex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-/]+/[\w\-\.]+(\.git)?$")]
|
||||
private static partial Regex REG_SSH2();
|
||||
|
||||
[GeneratedRegex(@"^git@([\w\.\-]+):([\w\-/]+/[\w\-\.]+)\.git$")]
|
||||
private static partial Regex REG_TO_VISIT_URL_CAPTURE();
|
||||
|
||||
private static readonly Regex[] URL_FORMATS = [
|
||||
REG_HTTPS(),
|
||||
REG_SSH1(),
|
||||
|
@ -43,5 +47,29 @@ namespace SourceGit.Models
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetVisitURL(out string url)
|
||||
{
|
||||
url = null;
|
||||
|
||||
if (URL.StartsWith("http", StringComparison.Ordinal))
|
||||
{
|
||||
if (URL.EndsWith(".git"))
|
||||
url = URL.Substring(0, URL.Length - 4);
|
||||
else
|
||||
url = URL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
var match = REG_TO_VISIT_URL_CAPTURE().Match(URL);
|
||||
if (match.Success)
|
||||
{
|
||||
url = $"https://{match.Groups[1].Value}/{match.Groups[2].Value}";
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue