tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
GitRemoteFeaturesBase.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Threading;
4using System.Threading.Tasks;
5
6using Microsoft.Extensions.Logging;
7
9
11{
16 {
18 public abstract string TestMergeRefSpecFormatter { get; }
19
21 public abstract string TestMergeLocalBranchNameFormatter { get; }
22
24 public abstract RemoteGitProvider? RemoteGitProvider { get; }
25
27 public string RemoteRepositoryOwner { get; }
28
30 public string RemoteRepositoryName { get; }
31
35 protected ILogger<GitRemoteFeaturesBase> Logger { get; }
36
40 readonly Dictionary<TestMergeParameters, Models.TestMerge> cachedLookups;
41
47 public GitRemoteFeaturesBase(ILogger<GitRemoteFeaturesBase> logger, Uri remoteUrl)
48 {
49 Logger = logger ?? throw new ArgumentNullException(nameof(logger));
50 ArgumentNullException.ThrowIfNull(remoteUrl);
51
52 RemoteRepositoryOwner = remoteUrl.Segments[1].TrimEnd('/');
53 RemoteRepositoryName = remoteUrl.Segments[2].TrimEnd('/');
54 if (RemoteRepositoryName.EndsWith(".git", StringComparison.OrdinalIgnoreCase))
56
57 cachedLookups = new Dictionary<TestMergeParameters, Models.TestMerge>();
58 }
59
61 public async ValueTask<Models.TestMerge> GetTestMerge(
62 TestMergeParameters parameters,
63 RepositorySettings repositorySettings,
64 CancellationToken cancellationToken)
65 {
66 ArgumentNullException.ThrowIfNull(parameters);
67 ArgumentNullException.ThrowIfNull(repositorySettings);
68
69 Models.TestMerge? result;
70 lock (cachedLookups)
71 if (cachedLookups.TryGetValue(parameters, out result))
72 Logger.LogTrace("Using cache for test merge #{testMergeNumber}", parameters.Number);
73
74 if (result == null)
75 {
76 Logger.LogTrace("Retrieving metadata for test merge #{testMergeNumber}...", parameters.Number);
77 result = await GetTestMergeImpl(parameters, repositorySettings, cancellationToken);
78 lock (cachedLookups)
79 if (!cachedLookups.TryAdd(parameters, result))
80 Logger.LogError("Race condition on adding test merge #{testMergeNumber}!", parameters.Number);
81 }
82
83 return result;
84 }
85
93 protected abstract ValueTask<Models.TestMerge> GetTestMergeImpl(
94 TestMergeParameters parameters,
95 RepositorySettings repositorySettings,
96 CancellationToken cancellationToken);
97 }
98}
Represents configurable settings for a git repository.
int Number
The number of the test merge source.
readonly Dictionary< TestMergeParameters, Models.TestMerge > cachedLookups
Cache of created Models.TestMerges.
ValueTask< Models.TestMerge > GetTestMergeImpl(TestMergeParameters parameters, RepositorySettings repositorySettings, CancellationToken cancellationToken)
Implementation of GetTestMerge(TestMergeParameters, RepositorySettings, CancellationToken).
string RemoteRepositoryOwner
If RemoteGitProvider is not RemoteGitProvider.Unknown this will be set with the owner of the reposito...
async ValueTask< Models.TestMerge > GetTestMerge(TestMergeParameters parameters, RepositorySettings repositorySettings, CancellationToken cancellationToken)
Retrieve the Models.TestMerge representation of given test merge parameters .A ValueTask<TResult> res...
string TestMergeRefSpecFormatter
Gets a formatter string which creates the remote refspec for fetching the HEAD of passed in test merg...
GitRemoteFeaturesBase(ILogger< GitRemoteFeaturesBase > logger, Uri remoteUrl)
Initializes a new instance of the GitRemoteFeaturesBase class.
ILogger< GitRemoteFeaturesBase > Logger
The ILogger for the GitRemoteFeaturesBase.
string RemoteRepositoryName
If RemoteGitProvider is not RemoteGitProvider.Unknown this will be set with the name of the repositor...
RemoteGitProvider
Indicates the remote git host.