2using System.Collections.Concurrent;
3using System.Collections.Generic;
4using System.Globalization;
7using System.Threading.Tasks;
10using GitLabApiClient.Models.MergeRequests.Responses;
11using GitLabApiClient.Models.Notes.Requests;
12using Microsoft.Extensions.Logging;
31 ILogger<GitLabRemoteDeploymentManager> logger,
32 Api.Models.Instance metadata,
43 CancellationToken cancellationToken)
45 ArgumentNullException.ThrowIfNull(repository);
46 ArgumentNullException.ThrowIfNull(repositorySettings);
47 ArgumentNullException.ThrowIfNull(revisionInformation);
51 Logger.LogTrace(
"No test merges to remove.");
55 var client = repositorySettings.AccessToken !=
null
59 var tasks = revisionInformation
64 $
"{repository.RemoteRepositoryOwner}/{repository.RemoteRepositoryName}",
66 .WaitAsync(cancellationToken));
69 await Task.WhenAll(tasks);
71 catch (
Exception ex) when (ex is not OperationCanceledException)
73 Logger.LogWarning(ex,
"Merge requests update check failed!");
76 var newList = revisionInformation.
ActiveTestMerges.Select(x => x.TestMerge).ToList();
78 MergeRequest? lastMerged =
null;
79 async ValueTask CheckRemoveMR(Task<MergeRequest> task)
81 var mergeRequest = await task;
82 if (mergeRequest.State != MergeRequestState.Merged)
86 if (await repository.
CommittishIsParent(mergeRequest.MergeCommitSha, cancellationToken))
88 if (lastMerged ==
null || lastMerged.ClosedAt < mergeRequest.ClosedAt)
89 lastMerged = mergeRequest;
92 potential => potential.Number == mergeRequest.Id));
96 foreach (var prTask
in tasks)
97 await CheckRemoveMR(prTask);
106 CancellationToken cancellationToken) => ValueTask.CompletedTask;
110 Api.Models.Internal.IGitRemoteInformation remoteInformation,
112 CancellationToken cancellationToken) => ValueTask.CompletedTask;
117 CancellationToken cancellationToken) => ValueTask.CompletedTask;
128 string remoteRepositoryOwner,
129 string remoteRepositoryName,
132 CancellationToken cancellationToken)
134 var client = repositorySettings.AccessToken !=
null
143 $
"{remoteRepositoryOwner}/{remoteRepositoryName}",
145 new CreateMergeRequestNoteRequest(comment))
146 .WaitAsync(cancellationToken);
148 catch (
Exception ex) when (ex is not OperationCanceledException)
150 Logger.LogWarning(ex,
"Error posting GitHub comment!");
159 string remoteRepositoryOwner,
160 string remoteRepositoryName,
161 bool updated) => String.Format(
162 CultureInfo.InvariantCulture,
163 "#### Test Merge {4}{0}{0}##### Server Instance{0}{5}{1}{0}{0}##### Revision{0}Origin: {6}{0}Merge Request: {2}{0}Server: {7}{3}",
165 repositorySettings.ShowTestMergeCommitters!.Value
167 CultureInfo.InvariantCulture,
168 "{0}{0}##### Merged By{0}{1}",
170 testMerge.MergedBy!.Name)
172 testMerge.TargetCommitSha,
173 testMerge.Comment != null
175 CultureInfo.InvariantCulture,
176 "{0}{0}##### Comment{0}{1}",
180 updated ?
"Updated" :
"Deployed",
string? AccessToken
The token/password to access the git repository with. Can also be a TGS encoded app private key....
Base class for implementing IRemoteDeploymentManagers.
Api.Models.Instance Metadata
The Api.Models.Instance for the BaseRemoteDeploymentManager.
readonly ConcurrentDictionary< long, Action< bool > > activationCallbacks
A map of CompileJob Api.Models.EntityId.Ids to activation callback Action<T1>s.
ILogger< BaseRemoteDeploymentManager > Logger
The ILogger for the BaseRemoteDeploymentManager.
IRemoteDeploymentManager for GitLab.com.
override async 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...
override ValueTask ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
override string FormatTestMerge(RepositorySettings repositorySettings, CompileJob compileJob, TestMerge testMerge, string remoteRepositoryOwner, string remoteRepositoryName, bool updated)
override async ValueTask CommentOnTestMergeSource(RepositorySettings repositorySettings, string remoteRepositoryOwner, string remoteRepositoryName, string comment, int testMergeNumber, CancellationToken cancellationToken)
override ValueTask StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
override ValueTask StartDeployment(Api.Models.Internal.IGitRemoteInformation remoteInformation, CompileJob compileJob, CancellationToken cancellationToken)
Start a deployment for a given compileJob .A ValueTask representing the running operation.
GitLabRemoteDeploymentManager(ILogger< GitLabRemoteDeploymentManager > logger, Api.Models.Instance metadata, ConcurrentDictionary< long, Action< bool > > activationCallbacks)
Initializes a new instance of the GitLabRemoteDeploymentManager class.
override ValueTask MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken)
override ValueTask FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
Fail a deployment for a given compileJob .A ValueTask representing the running operation.
GitLab IGitRemoteFeatures.
const string GitLabUrl
Url for main GitLab site.
Represents an on-disk git repository.
Task< bool > CommittishIsParent(string committish, CancellationToken cancellationToken)
Check if a given committish is a parent of the current Head.