2using System.Collections.Concurrent;
3using System.Collections.Generic;
6using System.Threading.Tasks;
8using Microsoft.Extensions.Logging;
34 protected ILogger<BaseRemoteDeploymentManager>
Logger {
get; }
48 ILogger<BaseRemoteDeploymentManager> logger,
49 Api.Models.Instance metadata,
52 Logger = logger ??
throw new ArgumentNullException(nameof(logger));
53 Metadata = metadata ??
throw new ArgumentNullException(nameof(metadata));
64 CancellationToken cancellationToken)
66 ArgumentNullException.ThrowIfNull(compileJob);
67 ArgumentNullException.ThrowIfNull(repositorySettings);
68 ArgumentNullException.ThrowIfNull(repoOwner);
69 ArgumentNullException.ThrowIfNull(repoName);
75 if ((previousRevisionInformation !=
null && previousRevisionInformation.
CommitSha == revisionInformation.CommitSha)
79 var previousTestMerges = (IEnumerable<RevInfoTestMerge>?)previousRevisionInformation?.ActiveTestMerges ?? Enumerable.Empty<
RevInfoTestMerge>();
80 var currentTestMerges = (IEnumerable<RevInfoTestMerge>?)revisionInformation.ActiveTestMerges ?? Enumerable.Empty<
RevInfoTestMerge>();
83 var addedTestMerges = currentTestMerges
84 .Select(x => x.TestMerge)
85 .Where(x => !previousTestMerges
86 .Any(y => y.TestMerge.Number == x.Number))
88 var removedTestMerges = previousTestMerges
89 .Select(x => x.TestMerge)
90 .Where(x => !currentTestMerges
91 .Any(y => y.TestMerge.Number == x.Number))
93 var updatedTestMerges = currentTestMerges
94 .Select(x => x.TestMerge)
95 .Where(x => previousTestMerges
96 .Any(y => y.TestMerge.Number == x.Number))
99 if (addedTestMerges.Count == 0 && removedTestMerges.Count == 0 && updatedTestMerges.Count == 0)
103 "Commenting on {addedCount} added, {removedCount} removed, and {updatedCount} updated test merge sources...",
104 addedTestMerges.Count,
105 removedTestMerges.Count,
106 updatedTestMerges.Count);
108 var tasks =
new List<ValueTask>(addedTestMerges.Count + updatedTestMerges.Count + removedTestMerges.Count);
109 foreach (var addedTestMerge
in addedTestMerges)
122 addedTestMerge.Number,
124 tasks.Add(addCommentTask);
127 foreach (var removedTestMerge
in removedTestMerges)
139 removedTestMerge.Number,
141 tasks.Add(removeCommentTask);
144 foreach (var updatedTestMerge
in updatedTestMerges)
157 updatedTestMerge.Number,
159 tasks.Add(updateCommentTask);
169 ArgumentNullException.ThrowIfNull(compileJob);
171 if (
activationCallbacks.TryGetValue(compileJob.Require(x => x.Id), out var activationCallback))
172 activationCallback(
true);
183 ArgumentNullException.ThrowIfNull(compileJob);
185 if (
activationCallbacks.TryRemove(compileJob.Require(x => x.Id), out var activationCallback))
186 activationCallback(
false);
196 CancellationToken cancellationToken);
201 ArgumentNullException.ThrowIfNull(compileJob);
203 var compileJobId = compileJob.Require(x => x.Id);
204 if (activationCallback !=
null && !
activationCallbacks.TryAdd(compileJobId, activationCallback))
205 Logger.LogError(
"activationCallbacks conflicted on CompileJob #{id}!", compileJobId);
212 Api.Models.Internal.IGitRemoteInformation remoteInformation,
214 CancellationToken cancellationToken);
254 string remoteRepositoryOwner,
255 string remoteRepositoryName,
271 string remoteRepositoryOwner,
272 string remoteRepositoryName);
286 string remoteRepositoryOwner,
287 string remoteRepositoryName,
290 CancellationToken cancellationToken);
Metadata about a server instance.
bool? PostTestMergeComment
If test merging should create a comment. Requires AccessToken to be set to function.
string? AccessToken
The token/password to access the git repository with. Can also be a TGS encoded app private key....
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.
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 ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
Implementation of ApplyDeployment(CompileJob, CancellationToken).
Api.Models.Instance Metadata
The Api.Models.Instance for the BaseRemoteDeploymentManager.
ValueTask FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
Fail a deployment for a given compileJob .A ValueTask representing the running operation.
const string DeploymentMsgHeaderStart
The header comment that begins every deployment message comment/note.
ValueTask StageDeployment(CompileJob compileJob, Action< bool >? activationCallback, CancellationToken cancellationToken)
Stage a given compileJob 's deployment.A ValueTask representing the running operation.
ValueTask MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken)
Implementation of MarkInactive(CompileJob, CancellationToken).
ValueTask MarkInactive(CompileJob compileJob, CancellationToken cancellationToken)
Mark the deplotment for a given compileJob as inactive.A Task representing the running operation.
ValueTask CommentOnTestMergeSource(RepositorySettings repositorySettings, string remoteRepositoryOwner, string remoteRepositoryName, string comment, int testMergeNumber, CancellationToken cancellationToken)
Create a comment of a given testMergeNumber 's source.
string FormatTestMerge(RepositorySettings repositorySettings, CompileJob compileJob, TestMerge testMerge, string remoteRepositoryOwner, string remoteRepositoryName, bool updated)
Formats a comment for a given testMerge .
ValueTask StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
Implementation of StageDeployment(CompileJob, Action<bool>, 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.
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.
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 IReadOnl...
string FormatTestMergeRemoval(RepositorySettings repositorySettings, CompileJob compileJob, TestMerge testMerge, string remoteRepositoryOwner, string remoteRepositoryName)
Formats a comment for a given testMerge removal.
ILogger< BaseRemoteDeploymentManager > Logger
The ILogger for the BaseRemoteDeploymentManager.
RevisionInformation RevisionInformation
See CompileJobResponse.RevisionInformation.
Many to many relationship for Models.RevisionInformation and Models.TestMerge.
Creates and updates remote deployments.
Represents an on-disk git repository.