feature: self host GitLab URLs in CommitLink (#1635)

This commit is contained in:
heartacker
2025-07-30 11:53:29 +08:00
committed by GitHub
parent df48678c7c
commit 2437475006
2 changed files with 9 additions and 2 deletions

View File

@@ -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/"));

View File

@@ -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();