mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-23 10:22:13 +08:00
feature: self host GitLab URLs in CommitLink (#1635)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class CommitLink
|
||||
public partial class CommitLink
|
||||
{
|
||||
public string Name { get; set; } = null;
|
||||
public string URLPrefix { get; set; } = null;
|
||||
@@ -14,6 +15,9 @@ namespace SourceGit.Models
|
||||
URLPrefix = prefix;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^(http|https)://[^/]*gitlab[^/]*(:[0-9]+)?.*$")]
|
||||
private static partial Regex REG_GITLAB();
|
||||
|
||||
public static List<CommitLink> Get(List<Remote> remotes)
|
||||
{
|
||||
var outs = new List<CommitLink>();
|
||||
@@ -28,7 +32,7 @@ namespace SourceGit.Models
|
||||
|
||||
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
|
||||
outs.Add(new($"GitHub ({trimmedUrl[19..]})", $"{url}/commit/"));
|
||||
else if (url.StartsWith("https://gitlab.", StringComparison.Ordinal))
|
||||
else if (REG_GITLAB().IsMatch(url))
|
||||
outs.Add(new($"GitLab ({trimmedUrl[(trimmedUrl[15..].IndexOf('/') + 16)..]})", $"{url}/-/commit/"));
|
||||
else if (url.StartsWith("https://gitee.com/", StringComparison.Ordinal))
|
||||
outs.Add(new($"Gitee ({trimmedUrl[18..]})", $"{url}/commit/"));
|
||||
|
||||
@@ -8,10 +8,13 @@ namespace SourceGit.Models
|
||||
{
|
||||
[GeneratedRegex(@"^https?://[^/]+/.+[^/\.]$")]
|
||||
private static partial Regex REG_HTTPS();
|
||||
|
||||
[GeneratedRegex(@"^git://[^/]+/.+[^/\.]$")]
|
||||
private static partial Regex REG_GIT();
|
||||
|
||||
[GeneratedRegex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:([a-zA-z0-9~%][\w\-\./~%]*)?[a-zA-Z0-9](\.git)?$")]
|
||||
private static partial Regex REG_SSH1();
|
||||
|
||||
[GeneratedRegex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/([a-zA-z0-9~%][\w\-\./~%]*)?[a-zA-Z0-9](\.git)?$")]
|
||||
private static partial Regex REG_SSH2();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user