5 Commits
Author SHA1 Message Date
kislovdm d6c7792a6c new code
Create and publish a Docker image / build-and-push-image (push) Failing after 13s
2024-02-07 14:52:20 +03:00
kislovdm c92e6f5ee9 new code
Create and publish a Docker image / build-and-push-image (push) Failing after 14s
2024-02-07 14:42:02 +03:00
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 48 additions and 16 deletions
+3 -1
View File
@@ -4,7 +4,9 @@ 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:
REGISTRY: ghcr.io
+41 -7
View File
@@ -39,11 +39,37 @@ 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 mrsToSameRelease = await _customClient.GetMergeRequestsByTargetBranch(mergeRequest.TargetBranch);
var sameMrs = mrsToSameRelease.Where(f => f.SourceBranch == mergeRequest.SourceBranch &&
f.TargetBranch == mergeRequest.TargetBranch &&
f.State == MergeRequestState.Merged).ToArray();
if (sameMrs.Any())
{
var mrUrls = string.Join("\r\n", sameMrs.Select(f=>f.WebUrl));
var message = $"Аналогичный MR ({sameMrs.First().WebUrl}) уже был одобрен и влит, автоматически одобряю текущий:\r\n{mrUrls}";
await _client.MergeRequests.CreateNoteAsync(mergeRequest.ProjectId, mergeRequest.Iid,
new CreateMergeRequestNoteRequest(message));
return 0;
}
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;
}
@@ -51,13 +77,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();
@@ -125,4 +146,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; } = new();
}
+3 -8
View File
@@ -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
{
@@ -12,7 +6,8 @@ namespace Approve.Checker.Gitlab
public string GitlabToken = Environment.GetEnvironmentVariable("GITLAB_TOKEN") ?? CheckAndThrow("GITLAB_TOKEN");
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 Approvers = Environment.GetEnvironmentVariable("APPROVERS_FILEPATH") ?? CheckAndThrow("APPROVERS_FILEPATH");
public string ReleaseCodeFreeze = Environment.GetEnvironmentVariable("RELEASE_CODEFREEZE") ?? "false";
private static string CheckAndThrow(string name)
{