2using System.Collections.Generic;
3using System.Globalization;
6using System.Threading.Tasks;
9using GitLabApiClient.Models.MergeRequests.Responses;
10using GitLabApiClient.Models.Notes.Requests;
11using Microsoft.Extensions.Logging;
30 : base(logger, metadata)
39 CancellationToken cancellationToken)
41 ArgumentNullException.ThrowIfNull(repository);
42 ArgumentNullException.ThrowIfNull(repositorySettings);
43 ArgumentNullException.ThrowIfNull(revisionInformation);
47 Logger.LogTrace(
"No test merges to remove.");
51 var client = repositorySettings.AccessToken !=
null
55 var tasks = revisionInformation
60 $
"{repository.RemoteRepositoryOwner}/{repository.RemoteRepositoryName}",
62 .WithToken(cancellationToken));
65 await Task.WhenAll(tasks);
67 catch (Exception ex) when (ex is not OperationCanceledException)
69 Logger.LogWarning(ex,
"Merge requests update check failed!");
72 var newList = revisionInformation.
ActiveTestMerges.Select(x => x.TestMerge).ToList();
74 MergeRequest lastMerged =
null;
75 async Task CheckRemoveMR(Task<MergeRequest> task)
77 var mergeRequest = await task;
78 if (mergeRequest.State != MergeRequestState.Merged)
82 if (await repository.
ShaIsParent(mergeRequest.MergeCommitSha, cancellationToken))
84 if (lastMerged ==
null || lastMerged.ClosedAt < mergeRequest.ClosedAt)
85 lastMerged = mergeRequest;
88 potential => potential.Number == mergeRequest.Id));
92 foreach (var prTask
in tasks)
93 await CheckRemoveMR(prTask);
102 CancellationToken cancellationToken) => Task.CompletedTask;
108 CancellationToken cancellationToken) => Task.CompletedTask;
118 Api.Models.Internal.IGitRemoteInformation remoteInformation,
120 CancellationToken cancellationToken) => Task.CompletedTask;
125 string remoteRepositoryOwner,
126 string remoteRepositoryName,
129 CancellationToken cancellationToken)
131 var client = repositorySettings.AccessToken !=
null
140 $
"{remoteRepositoryOwner}/{remoteRepositoryName}",
142 new CreateMergeRequestNoteRequest(comment))
143 .WithToken(cancellationToken);
145 catch (Exception ex) when (ex is not OperationCanceledException)
147 Logger.LogWarning(ex,
"Error posting GitHub comment!");
156 string remoteRepositoryOwner,
157 string remoteRepositoryName,
158 bool updated) => String.Format(
159 CultureInfo.InvariantCulture,
160 "#### Test Merge {4}{0}{0}##### Server Instance{0}{5}{1}{0}{0}##### Revision{0}Origin: {6}{0}Merge Request: {2}{0}Server: {7}{3}",
162 repositorySettings.ShowTestMergeCommitters.Value
164 CultureInfo.InvariantCulture,
165 "{0}{0}##### Merged By{0}{1}",
167 testMerge.MergedBy.Name)
169 testMerge.TargetCommitSha,
170 testMerge.Comment !=
null
172 CultureInfo.InvariantCulture,
173 "{0}{0}##### Comment{0}{1}",
177 updated ?
"Updated" :
"Deployed",
179 compileJob.RevisionInformation.OriginCommitSha,
180 compileJob.RevisionInformation.CommitSha);
string? AccessToken
The token/password to access the git repository with.
Base class for implementing IRemoteDeploymentManagers.
Api.Models.Instance Metadata
The Api.Models.Instance for the BaseRemoteDeploymentManager.
ILogger< BaseRemoteDeploymentManager > Logger
The ILogger for the BaseRemoteDeploymentManager.
IRemoteDeploymentManager for GitLab.com.
override string FormatTestMerge(RepositorySettings repositorySettings, CompileJob compileJob, TestMerge testMerge, string remoteRepositoryOwner, string remoteRepositoryName, bool updated)
Formats a comment for a given testMerge . A Task representing the running operation.
override Task ApplyDeployment(CompileJob compileJob, CompileJob oldCompileJob, CancellationToken cancellationToken)
Stage a given compileJob 's deployment. A Task representing the running operation.
GitLabRemoteDeploymentManager(ILogger< GitLabRemoteDeploymentManager > logger, Api.Models.Instance metadata)
Initializes a new instance of the GitLabRemoteDeploymentManager class.
override async Task CommentOnTestMergeSource(RepositorySettings repositorySettings, string remoteRepositoryOwner, string remoteRepositoryName, string comment, int testMergeNumber, CancellationToken cancellationToken)
Create a comment of a given testMergeNumber 's source. A Task representing the running operation.
override Task MarkInactive(CompileJob compileJob, CancellationToken cancellationToken)
Mark the deplotment for a given compileJob as inactive. A Task representing the running operation.
override Task StageDeployment(CompileJob compileJob, CancellationToken cancellationToken)
Stage a given compileJob 's deployment. A Task representing the running operation.
override Task StartDeployment(Api.Models.Internal.IGitRemoteInformation remoteInformation, CompileJob compileJob, CancellationToken cancellationToken)
Start a deployment for a given compileJob . A Task representing the running operation.
override async Task< IReadOnlyCollection< TestMerge > > RemoveMergedTestMerges(IRepository repository, RepositorySettings repositorySettings, RevisionInformation revisionInformation, CancellationToken cancellationToken)
Get the updated list of TestMerges for an origin merge. A Task<TResult> resulting in the IReadOnlyCol...
override Task FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
Fail a deployment for a given compileJob . A Task representing the running operation.
GitLab IGitRemoteFeatures.
const string GitLabUrl
Url for main GitLab site.
Represents an on-disk git repository.
Task< bool > ShaIsParent(string sha, CancellationToken cancellationToken)
Check if a given sha is a parent of the current Head.