2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Text.RegularExpressions;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Models
|
|
|
|
|
{
|
|
|
|
|
public partial class Remote
|
|
|
|
|
{
|
|
|
|
|
|
2024-03-16 02:09:27 -07:00
|
|
|
|
[GeneratedRegex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$")]
|
|
|
|
|
private static partial Regex regex1();
|
|
|
|
|
|
|
|
|
|
[GeneratedRegex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-]+/[\w\-\.]+\.git$")]
|
|
|
|
|
private static partial Regex regex2();
|
|
|
|
|
[GeneratedRegex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$")]
|
|
|
|
|
private static partial Regex regex3();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private static readonly Regex[] URL_FORMATS = [
|
2024-03-16 02:09:27 -07:00
|
|
|
|
regex1(),
|
|
|
|
|
regex2(),
|
|
|
|
|
regex3(),
|
2024-02-05 23:08:37 -08:00
|
|
|
|
];
|
|
|
|
|
|
2021-04-29 05:05:55 -07:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string URL { get; set; }
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static bool IsSSH(string url)
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
|
|
|
return false;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
for (int i = 1; i < URL_FORMATS.Length; i++)
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (URL_FORMATS[i].IsMatch(url))
|
|
|
|
|
return true;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static bool IsValidURL(string url)
|
|
|
|
|
{
|
|
|
|
|
foreach (var fmt in URL_FORMATS)
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (fmt.IsMatch(url))
|
|
|
|
|
return true;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|