Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Models/CommitLink.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,6 +15,9 @@ public CommitLink(string name, string prefix)
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>();
Expand All @@ -28,7 +32,7 @@ public static List<CommitLink> Get(List<Remote> remotes)

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/"));
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Remote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ public partial class Remote
{
[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();

Expand Down
Loading