tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
GitRemoteFeaturesFactory.cs
Go to the documentation of this file.
1using System;
2
3using Microsoft.Extensions.Logging;
4
7
9{
12 {
17
21 readonly ILoggerFactory loggerFactory;
22
26 readonly ILogger<GitRemoteFeaturesFactory> logger;
27
36 ILoggerFactory loggerFactory,
37 ILogger<GitRemoteFeaturesFactory> logger)
38 {
39 this.gitHubServiceFactory = gitHubServiceFactory ?? throw new ArgumentNullException(nameof(gitHubServiceFactory));
40 this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
41 this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
42 }
43
46 {
47 ArgumentNullException.ThrowIfNull(repository);
48 return CreateGitRemoteFeatures(repository.Origin);
49 }
50
53 {
54 ArgumentNullException.ThrowIfNull(origin);
55
56 var remoteGitProvider = ParseRemoteGitProviderFromOrigin(origin);
57 return remoteGitProvider switch
58 {
59 RemoteGitProvider.GitHub => new GitHubRemoteFeatures(
61 loggerFactory.CreateLogger<GitHubRemoteFeatures>(),
62 origin),
63 RemoteGitProvider.GitLab => new GitLabRemoteFeatures(
64 loggerFactory.CreateLogger<GitLabRemoteFeatures>(),
65 origin),
66 RemoteGitProvider.Unknown => new DefaultGitRemoteFeatures(),
67 _ => throw new InvalidOperationException($"Unknown RemoteGitProvider: {remoteGitProvider}!"),
68 };
69 }
70
73 {
74 ArgumentNullException.ThrowIfNull(origin);
75
76 switch (origin.Host.ToUpperInvariant())
77 {
78 case "GITHUB.COM":
79 case "WWW.GITHUB.COM":
80 case "GIT.GITHUB.COM":
81 return RemoteGitProvider.GitHub;
82 case "GITLAB.COM":
83 case "WWW.GITLAB.COM":
84 case "GIT.GITLAB.COM":
85 return RemoteGitProvider.GitLab;
86 default:
87 logger.LogDebug("Unknown git remote: {origin}", origin);
88 return RemoteGitProvider.Unknown;
89 }
90 }
91 }
92}
RemoteGitProvider ParseRemoteGitProviderFromOrigin(Uri origin)
Gets the RemoteGitProvider for a given origin .The RemoteGitProvider of the origin .
IGitRemoteFeatures CreateGitRemoteFeatures(Uri origin)
Create the IGitRemoteFeatures for a given origin .A new IGitRemoteFeatures instance.
readonly ILoggerFactory loggerFactory
The ILoggerFactory for the GitRemoteFeaturesFactory.
readonly ILogger< GitRemoteFeaturesFactory > logger
The ILogger for the GitRemoteFeaturesFactory.
GitRemoteFeaturesFactory(IGitHubServiceFactory gitHubServiceFactory, ILoggerFactory loggerFactory, ILogger< GitRemoteFeaturesFactory > logger)
Initializes a new instance of the GitRemoteFeaturesFactory class.
IGitRemoteFeatures CreateGitRemoteFeatures(IRepository repository)
Create the IGitRemoteFeatures for a given repository .A new IGitRemoteFeatures instance.
readonly IGitHubServiceFactory gitHubServiceFactory
The IGitHubServiceFactory for the GitRemoteFeaturesFactory.
Represents an on-disk git repository.
Uri Origin
The current origin remote the IRepository is using.
RemoteGitProvider
Indicates the remote git host.