tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
GitLabRemoteFeatures.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
5using GitLabApiClient;
6using Microsoft.Extensions.Logging;
7
9
11{
16 {
21 public const string GitLabUrl = "https://gitlab.com";
22
24 public override string TestMergeRefSpecFormatter => "merge-requests/{0}/head:{1}";
25
27 public override string TestMergeLocalBranchNameFormatter => "merge-requests/{0}/headrefs/heads/{1}";
28
30 public override RemoteGitProvider? RemoteGitProvider => Api.Models.RemoteGitProvider.GitLab;
31
37 public GitLabRemoteFeatures(ILogger<GitLabRemoteFeatures> logger, Uri remoteUrl)
38 : base(logger, remoteUrl)
39 {
40 }
41
43 protected override async ValueTask<Models.TestMerge> GetTestMergeImpl(
44 TestMergeParameters parameters,
45 RepositorySettings repositorySettings,
46 CancellationToken cancellationToken)
47 {
48 var client = repositorySettings.AccessToken != null
49 ? new GitLabClient(GitLabUrl, repositorySettings.AccessToken)
50 : new GitLabClient(GitLabUrl);
51
52 try
53 {
54 var mr = await client
55 .MergeRequests
56 .GetAsync($"{RemoteRepositoryOwner}/{RemoteRepositoryName}", parameters.Number)
57 .WaitAsync(cancellationToken);
58
59 var revisionToUse = parameters.TargetCommitSha == null
60 || mr.Sha.StartsWith(parameters.TargetCommitSha, StringComparison.OrdinalIgnoreCase)
61 ? mr.Sha
62 : parameters.TargetCommitSha;
63
64 return new Models.TestMerge
65 {
66 Author = mr.Author.Username,
67 BodyAtMerge = mr.Description,
68 TitleAtMerge = mr.Title,
69 Comment = parameters.Comment,
70 Number = parameters.Number,
71 TargetCommitSha = mr.Sha,
72 Url = mr.WebUrl,
73 };
74 }
75 catch (Exception ex)
76 {
77 Logger.LogWarning(ex, "Error retrieving merge request metadata!");
78
79 return new Models.TestMerge
80 {
81 Author = ex.Message,
82 BodyAtMerge = ex.Message,
83 TitleAtMerge = ex.Message,
84 Comment = parameters.Comment,
85 Number = parameters.Number,
86 TargetCommitSha = parameters.TargetCommitSha,
87 Url = $"https://gitlab.com/{RemoteRepositoryOwner}/{RemoteRepositoryName}/-/merge_requests/{parameters.Number}",
88 };
89 }
90 }
91 }
92}
string? Author
The author of the test merge source.
Represents configurable settings for a git repository.
string? AccessToken
The token/password to access the git repository with. Can also be a TGS encoded app private key....
virtual ? string TargetCommitSha
The sha of the test merge revision to merge. If not specified, the latest commit from the source will...
string? Comment
Optional comment about the test.
int Number
The number of the test merge source.
override async ValueTask< Models.TestMerge > GetTestMergeImpl(TestMergeParameters parameters, RepositorySettings repositorySettings, CancellationToken cancellationToken)
GitLabRemoteFeatures(ILogger< GitLabRemoteFeatures > logger, Uri remoteUrl)
Initializes a new instance of the GitLabRemoteFeatures class.
override string TestMergeRefSpecFormatter
Gets a formatter string which creates the remote refspec for fetching the HEAD of passed in test merg...
ILogger< GitRemoteFeaturesBase > Logger
The ILogger for the GitRemoteFeaturesBase.
RemoteGitProvider
Indicates the remote git host.