2using System.Collections.Concurrent;
3using System.Collections.Generic;
6using System.Threading.Tasks;
8using Microsoft.Extensions.Logging;
29 protected ILogger<BaseRemoteDeploymentManager>
Logger {
get; }
43 ILogger<BaseRemoteDeploymentManager> logger,
44 Api.Models.Instance metadata,
47 Logger = logger ??
throw new ArgumentNullException(nameof(logger));
48 Metadata = metadata ??
throw new ArgumentNullException(nameof(metadata));
59 CancellationToken cancellationToken)
61 ArgumentNullException.ThrowIfNull(compileJob);
62 ArgumentNullException.ThrowIfNull(repositorySettings);
63 ArgumentNullException.ThrowIfNull(repoOwner);
64 ArgumentNullException.ThrowIfNull(repoName);
70 if ((previousRevisionInformation !=
null && previousRevisionInformation.
CommitSha == deployedRevisionInformation.CommitSha)
75 previousRevisionInformation.ActiveTestMerges ??=
new List<RevInfoTestMerge>();
77 deployedRevisionInformation.ActiveTestMerges ??=
new List<RevInfoTestMerge>();
80 var addedTestMerges = deployedRevisionInformation
82 .Select(x => x.TestMerge)
83 .Where(x => !previousRevisionInformation
85 .Any(y => y.TestMerge.Number == x.Number))
87 var removedTestMerges = previousRevisionInformation
89 .Select(x => x.TestMerge)
90 .Where(x => !deployedRevisionInformation
92 .Any(y => y.TestMerge.Number == x.Number))
94 var updatedTestMerges = deployedRevisionInformation
96 .Select(x => x.TestMerge)
97 .Where(x => previousRevisionInformation
99 .Any(y => y.TestMerge.Number == x.Number))
102 if (addedTestMerges.Count == 0 && removedTestMerges.Count == 0 && updatedTestMerges.Count == 0)
106 "Commenting on {addedCount} added, {removedCount} removed, and {updatedCount} updated test merge sources...",
107 addedTestMerges.Count,
108 removedTestMerges.Count,
109 updatedTestMerges.Count);
111 var tasks =
new List<ValueTask>(addedTestMerges.Count + updatedTestMerges.Count + removedTestMerges.Count);
112 foreach (var addedTestMerge
in addedTestMerges)
125 addedTestMerge.Number,
127 tasks.Add(addCommentTask);
130 foreach (var removedTestMerge
in removedTestMerges)
136 "#### Test Merge Removed",
137 removedTestMerge.Number,
139 tasks.Add(removeCommentTask);
142 foreach (var updatedTestMerge
in updatedTestMerges)
155 updatedTestMerge.Number,
157 tasks.Add(updateCommentTask);
167 ArgumentNullException.ThrowIfNull(compileJob);
169 if (
activationCallbacks.TryGetValue(compileJob.Require(x => x.Id), out var activationCallback))
170 activationCallback(
true);
181 ArgumentNullException.ThrowIfNull(compileJob);
183 if (
activationCallbacks.TryRemove(compileJob.Require(x => x.Id), out var activationCallback))
184 activationCallback(
false);
194 CancellationToken cancellationToken);
199 ArgumentNullException.ThrowIfNull(compileJob);
201 var compileJobId = compileJob.Require(x => x.Id);
202 if (activationCallback !=
null && !
activationCallbacks.TryAdd(compileJobId, activationCallback))
203 Logger.LogError(
"activationCallbacks conflicted on CompileJob #{id}!", compileJobId);
210 Api.Models.Internal.IGitRemoteInformation remoteInformation,
212 CancellationToken cancellationToken);
252 string remoteRepositoryOwner,
253 string remoteRepositoryName,
268 string remoteRepositoryOwner,
269 string remoteRepositoryName,
272 CancellationToken cancellationToken);
Metadata about a server instance.
string? AccessToken
The token/password to access the git repository with.
bool? PostTestMergeComment
If test merging should create a comment. Requires AccessToken to be set to function.
Extension methods for the ValueTask and ValueTask<TResult> classes.
static async ValueTask WhenAll(IEnumerable< ValueTask > tasks)
Fully await a given list of tasks .
Base class for implementing IRemoteDeploymentManagers.
Api.Models.Instance Metadata
The Api.Models.Instance for the BaseRemoteDeploymentManager.
abstract ValueTask StartDeployment(Api.Models.Internal.IGitRemoteInformation remoteInformation, CompileJob compileJob, CancellationToken cancellationToken)
Start a deployment for a given compileJob . A ValueTask representing the running operation.
ValueTask StageDeployment(CompileJob compileJob, Action< bool >? activationCallback, CancellationToken cancellationToken)
Stage a given compileJob 's deployment. A ValueTask representing the running operation.
abstract string FormatTestMerge(RepositorySettings repositorySettings, CompileJob compileJob, TestMerge testMerge, string remoteRepositoryOwner, string remoteRepositoryName, bool updated)
Formats a comment for a given testMerge .
ValueTask MarkInactive(CompileJob compileJob, CancellationToken cancellationToken)
Mark the deplotment for a given compileJob as inactive. A Task representing the running operation.
abstract ValueTask CommentOnTestMergeSource(RepositorySettings repositorySettings, string remoteRepositoryOwner, string remoteRepositoryName, string comment, int testMergeNumber, CancellationToken cancellationToken)
Create a comment of a given testMergeNumber 's source.
abstract ValueTask MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken)
Implementation of MarkInactive(CompileJob, CancellationToken).
readonly ConcurrentDictionary< long, Action< bool > > activationCallbacks
A map of CompileJob Api.Models.EntityId.Ids to activation callback Action<T1>s.
BaseRemoteDeploymentManager(ILogger< BaseRemoteDeploymentManager > logger, Api.Models.Instance metadata, ConcurrentDictionary< long, Action< bool > > activationCallbacks)
Initializes a new instance of the BaseRemoteDeploymentManager class.
abstract ValueTask ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
Implementation of ApplyDeployment(CompileJob, CancellationToken).
abstract ValueTask StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
Implementation of StageDeployment(CompileJob, Action<bool>, CancellationToken).
async ValueTask PostDeploymentComments(CompileJob compileJob, RevisionInformation? previousRevisionInformation, RepositorySettings repositorySettings, string? repoOwner, string? repoName, CancellationToken cancellationToken)
Post deployment comments to the test merge ticket. A ValueTask representing the running operation.
ValueTask ApplyDeployment(CompileJob compileJob, CancellationToken cancellationToken)
Stage a given compileJob 's deployment. A ValueTask representing the running operation.
abstract ValueTask< IReadOnlyCollection< TestMerge > > RemoveMergedTestMerges(IRepository repository, RepositorySettings repositorySettings, RevisionInformation revisionInformation, CancellationToken cancellationToken)
Get the updated list of TestMerges for an origin merge. A ValueTask<TResult> resulting in the IReadOn...
abstract ValueTask FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
Fail a deployment for a given compileJob . A ValueTask representing the running operation.
ILogger< BaseRemoteDeploymentManager > Logger
The ILogger for the BaseRemoteDeploymentManager.
RevisionInformation RevisionInformation
See CompileJobResponse.RevisionInformation.
Creates and updates remote deployments.
Represents an on-disk git repository.