2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Text.RegularExpressions;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
namespace SourceGit.Models {
|
2021-04-29 05:05:55 -07:00
|
|
|
|
public class Remote {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private static readonly Regex[] URL_FORMATS = [
|
|
|
|
|
new Regex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$"),
|
|
|
|
|
new Regex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-]+/[\w\-\.]+\.git$"),
|
|
|
|
|
new Regex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$"),
|
|
|
|
|
];
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
public static bool IsSSH(string url) {
|
|
|
|
|
if (string.IsNullOrWhiteSpace(url)) return false;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < URL_FORMATS.Length; i++) {
|
|
|
|
|
if (URL_FORMATS[i].IsMatch(url)) return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsValidURL(string url) {
|
|
|
|
|
foreach (var fmt in URL_FORMATS) {
|
|
|
|
|
if (fmt.IsMatch(url)) return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|