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-04-06 03:11:49 -07:00
|
|
|
|
[GeneratedRegex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-/]+/[\w\-\.]+\.git$")]
|
|
|
|
|
private static partial Regex REG_HTTPS();
|
2024-05-20 23:35:14 -07:00
|
|
|
|
[GeneratedRegex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-/]+/[\w\-\.]+\.git$")]
|
2024-04-06 03:11:49 -07:00
|
|
|
|
private static partial Regex REG_SSH1();
|
2024-05-20 23:35:14 -07:00
|
|
|
|
[GeneratedRegex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-/]+/[\w\-\.]+\.git$")]
|
2024-04-06 03:11:49 -07:00
|
|
|
|
private static partial Regex REG_SSH2();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private static readonly Regex[] URL_FORMATS = [
|
2024-04-06 03:11:49 -07:00
|
|
|
|
REG_HTTPS(),
|
|
|
|
|
REG_SSH1(),
|
|
|
|
|
REG_SSH2(),
|
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
|
|
|
|
}
|