3 Commits
Author SHA1 Message Date
kislovdm 8d56dbf2b3 new code
Create and publish a Docker image / build-and-push-image (push) Failing after 15s
2024-02-07 14:29:13 +03:00
kislovdm 1d127cadd3 ok
Create and publish a Docker image / build-and-push-image (push) Failing after 14s
2024-02-07 13:56:26 +03:00
monster 97e81c3af4 Update blank.yml
Create and publish a Docker image / build-and-push-image (push) Failing after 14s
2024-02-07 13:31:39 +03:00
4 changed files with 34 additions and 16 deletions
+2
View File
@@ -4,6 +4,8 @@ name: Create and publish a Docker image
on: on:
push: push:
branches: [ "master" ] 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. # 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: env:
+27 -7
View File
@@ -39,11 +39,23 @@ public class App : IApp
Console.WriteLine("Not in MergeRequest. Exiting."); Console.WriteLine("Not in MergeRequest. Exiting.");
return 0; return 0;
} }
var approversDict = ParseApprovers();
if (approversDict is null)
{
return -1;
}
var mrId = int.Parse(_settings.MrPath.Split('!')[1]); var mrId = int.Parse(_settings.MrPath.Split('!')[1]);
var mergeRequest = await _client.MergeRequests.GetAsync(_settings.ProjectId, mrId); var mergeRequest = await _client.MergeRequests.GetAsync(_settings.ProjectId, mrId);
var commit = await _client.Commits.GetAsync(_settings.ProjectId, mergeRequest.Sha); 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; return -1;
} }
@@ -51,13 +63,8 @@ public class App : IApp
return 0; 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 emojis = await _client.MergeRequests.GetAwardEmojisAsync(_settings.ProjectId, mergeRequest.Iid);
var sb = new StringBuilder(); var sb = new StringBuilder();
@@ -125,4 +132,17 @@ public class App : IApp
return null; 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 class ApproversDto
{ {
public bool ForCodeFreeze { get; set; }
public int CountApprovers { get; set; } = 1; public int CountApprovers { get; set; } = 1;
public List<string> Users { get; set; } = new(); public List<string> Users { get; set; } = new();
} }
+2 -7
View File
@@ -1,10 +1,4 @@
using System; namespace Approve.Checker.Gitlab
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Approve.Checker.Gitlab
{ {
public class Settings public class Settings
{ {
@@ -13,6 +7,7 @@ namespace Approve.Checker.Gitlab
public string MrPath = Environment.GetEnvironmentVariable("CI_OPEN_MERGE_REQUESTS")!; public string MrPath = Environment.GetEnvironmentVariable("CI_OPEN_MERGE_REQUESTS")!;
public string ProjectId = Environment.GetEnvironmentVariable("CI_PROJECT_ID") ?? CheckAndThrow("CI_PROJECT_ID"); public string ProjectId = Environment.GetEnvironmentVariable("CI_PROJECT_ID") ?? CheckAndThrow("CI_PROJECT_ID");
public string Approvers = Environment.GetEnvironmentVariable("APPROVERS_FILEPATH") ?? CheckAndThrow("APPROVERS_FILEPATH"); public string Approvers = Environment.GetEnvironmentVariable("APPROVERS_FILEPATH") ?? CheckAndThrow("APPROVERS_FILEPATH");
public string ReleaseCodeFreeze = Environment.GetEnvironmentVariable("RELEASE_CODEFREEZE") ?? "false";
private static string CheckAndThrow(string name) private static string CheckAndThrow(string name)
{ {