Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d56dbf2b3 | ||
|
|
1d127cadd3 | ||
|
|
97e81c3af4 | ||
|
|
071aa73015 |
@@ -4,6 +4,8 @@ name: Create and publish a Docker image
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
|
||||
env:
|
||||
|
||||
+27
-12
@@ -23,11 +23,6 @@ public class App : IApp
|
||||
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
|
||||
};
|
||||
_settings = new Settings();
|
||||
if (string.IsNullOrEmpty(_settings.GitlabUrl))
|
||||
{
|
||||
Console.WriteLine("CI_SERVER_URL is not defined.");
|
||||
return;
|
||||
}
|
||||
_client = new GitLabClient(_settings.GitlabUrl, _settings.GitlabToken, httpHandler);
|
||||
_customClient = new GitlabCustomClient(_settings.GitlabUrl, _settings.GitlabToken, httpHandler);
|
||||
}
|
||||
@@ -44,11 +39,23 @@ public class App : IApp
|
||||
Console.WriteLine("Not in MergeRequest. Exiting.");
|
||||
return 0;
|
||||
}
|
||||
var approversDict = ParseApprovers();
|
||||
if (approversDict is null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var mrId = int.Parse(_settings.MrPath.Split('!')[1]);
|
||||
|
||||
var mergeRequest = await _client.MergeRequests.GetAsync(_settings.ProjectId, mrId);
|
||||
var commit = await _client.Commits.GetAsync(_settings.ProjectId, mergeRequest.Sha);
|
||||
if (!await IsApproved(mergeRequest, commit))
|
||||
|
||||
var isCodeFreezePeriod = _settings.ReleaseCodeFreeze != "true";
|
||||
var periodDescription = isCodeFreezePeriod ? "Code-Freeze. Restrictions may apply" : "Normal";
|
||||
Console.WriteLine($"Current period is {periodDescription}.");
|
||||
|
||||
approversDict = FilterApprovers(approversDict, isCodeFreezePeriod);
|
||||
if (!await IsApproved(mergeRequest, commit, approversDict))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -56,13 +63,8 @@ public class App : IApp
|
||||
return 0;
|
||||
}
|
||||
|
||||
private async Task<bool> IsApproved(MergeRequest mergeRequest, Commit commit)
|
||||
private async Task<bool> IsApproved(MergeRequest mergeRequest, Commit commit, Dictionary<string, ApproversDto> approversDict)
|
||||
{
|
||||
var approversDict = ParseApprovers();
|
||||
if (approversDict is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var emojis = await _client.MergeRequests.GetAwardEmojisAsync(_settings.ProjectId, mergeRequest.Iid);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
@@ -130,4 +132,17 @@ public class App : IApp
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, ApproversDto> FilterApprovers(Dictionary<string, ApproversDto> approvers, bool isCodeFreezePeriod)
|
||||
{
|
||||
var result = new Dictionary<string, ApproversDto>();
|
||||
foreach (var approversDto in approvers)
|
||||
{
|
||||
if (approversDto.Value.ForCodeFreeze == isCodeFreezePeriod)
|
||||
{
|
||||
result.Add(approversDto.Key, approversDto.Value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace Approve.Checker.Gitlab;
|
||||
|
||||
public class ApproversDto
|
||||
{
|
||||
public bool ForCodeFreeze { get; set; }
|
||||
public int CountApprovers { get; set; } = 1;
|
||||
public List<string> Users { get; set; }
|
||||
public List<string> Users { get; set; } = new();
|
||||
}
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Approve.Checker.Gitlab
|
||||
namespace Approve.Checker.Gitlab
|
||||
{
|
||||
public class Settings
|
||||
{
|
||||
@@ -13,6 +7,7 @@ namespace Approve.Checker.Gitlab
|
||||
public string MrPath = Environment.GetEnvironmentVariable("CI_OPEN_MERGE_REQUESTS")!;
|
||||
public string ProjectId = Environment.GetEnvironmentVariable("CI_PROJECT_ID") ?? CheckAndThrow("CI_PROJECT_ID");
|
||||
public string Approvers = Environment.GetEnvironmentVariable("APPROVERS_FILEPATH") ?? CheckAndThrow("APPROVERS_FILEPATH");
|
||||
public string ReleaseCodeFreeze = Environment.GetEnvironmentVariable("RELEASE_CODEFREEZE") ?? "false";
|
||||
|
||||
private static string CheckAndThrow(string name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user