-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathCommitLink.cs
More file actions
51 lines (45 loc) · 2.08 KB
/
CommitLink.cs
File metadata and controls
51 lines (45 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
namespace SourceGit.Models
{
public class CommitLink
{
public string Name { get; } = null;
public string URLPrefix { get; } = null;
public CommitLink(string name, string prefix)
{
Name = name;
URLPrefix = prefix;
}
public static List<CommitLink> Get(List<Remote> remotes)
{
var outs = new List<CommitLink>();
foreach (var remote in remotes)
{
if (remote.TryGetVisitURL(out var link))
{
var uri = new Uri(link, UriKind.Absolute);
var host = uri.Host;
var route = uri.AbsolutePath.TrimStart('/');
if (host.Equals("github.com", StringComparison.Ordinal))
outs.Add(new($"GitHub ({route})", $"{link}/commit/"));
else if (host.Contains("gitlab", StringComparison.Ordinal))
outs.Add(new($"GitLab ({route})", $"{link}/-/commit/"));
else if (host.Equals("gitee.com", StringComparison.Ordinal))
outs.Add(new($"Gitee ({route})", $"{link}/commit/"));
else if (host.Equals("bitbucket.org", StringComparison.Ordinal))
outs.Add(new($"BitBucket ({route})", $"{link}/commits/"));
else if (host.Equals("codeberg.org", StringComparison.Ordinal))
outs.Add(new($"Codeberg ({route})", $"{link}/commit/"));
else if (host.Equals("gitea.org", StringComparison.Ordinal))
outs.Add(new($"Gitea ({route})", $"{link}/commit/"));
else if (host.Equals("git.sr.ht", StringComparison.Ordinal))
outs.Add(new($"sourcehut ({route})", $"{link}/commit/"));
else if (host.Equals("gitcode.com", StringComparison.Ordinal))
outs.Add(new($"GitCode ({route})", $"{link}/commit/"));
}
}
return outs;
}
}
}