diff --git a/NGitLab.Mock/Clients/PipelineClient.cs b/NGitLab.Mock/Clients/PipelineClient.cs index 065e3e25..97c028c6 100644 --- a/NGitLab.Mock/Clients/PipelineClient.cs +++ b/NGitLab.Mock/Clients/PipelineClient.cs @@ -291,5 +291,19 @@ public GitLabCollectionResponse GetVariablesAsync(int pipeline { return GitLabCollectionResponse.Create(GetVariables(pipelineId)); } + + public Task RetryAsync(int pipelineId, CancellationToken cancellationToken = default) + { + using (Context.BeginOperationScope()) + { + var jobs = _jobClient.GetJobs(JobScopeMask.Failed).Where(j => j.Pipeline.Id == pipelineId); + foreach (var job in jobs) + { + _jobClient.RunAction(job.Id, JobAction.Retry); + } + + return Task.FromResult(this[pipelineId]); + } + } } } diff --git a/NGitLab.Tests/PipelineTests.cs b/NGitLab.Tests/PipelineTests.cs index bdf2ff38..70892d3a 100644 --- a/NGitLab.Tests/PipelineTests.cs +++ b/NGitLab.Tests/PipelineTests.cs @@ -200,13 +200,30 @@ public async Task Test_get_triggered_pipeline_variables() var trigger = triggers.Create("Test Trigger"); var ciJobToken = trigger.Token; - var pipeline = pipelineClient.CreatePipelineWithTrigger(ciJobToken, project.DefaultBranch, new Dictionary(StringComparer.InvariantCulture) { { "Test", "HelloWorld" } }); + var pipeline = pipelineClient.CreatePipelineWithTrigger(ciJobToken, project.DefaultBranch, new Dictionary(StringComparer.Ordinal) { { "Test", "HelloWorld" } }); var variables = pipelineClient.GetVariables(pipeline.Id); Assert.IsTrue(variables.Any(v => - v.Key.Equals("Test", StringComparison.InvariantCulture) && - v.Value.Equals("HelloWorld", StringComparison.InvariantCulture))); + v.Key.Equals("Test", StringComparison.Ordinal) && + v.Value.Equals("HelloWorld", StringComparison.Ordinal))); + } + + [Test] + [NGitLabRetry] + public async Task Test_retry() + { + using var context = await GitLabTestContext.CreateAsync(); + var project = context.CreateProject(); + var pipelineClient = context.Client.GetPipelines(project.Id); + JobTests.AddGitLabCiFile(context.Client, project); + + var triggers = context.Client.GetTriggers(project.Id); + var trigger = triggers.Create("Test Trigger"); + var ciJobToken = trigger.Token; + + var pipeline = pipelineClient.CreatePipelineWithTrigger(ciJobToken, project.DefaultBranch, new Dictionary(StringComparer.Ordinal) { { "Test", "HelloWorld" } }); + var retriedPipeline = pipelineClient.RetryAsync(pipeline.Id); } } } diff --git a/NGitLab/IPipelineClient.cs b/NGitLab/IPipelineClient.cs index 151d0ee5..5240b9d0 100644 --- a/NGitLab/IPipelineClient.cs +++ b/NGitLab/IPipelineClient.cs @@ -115,5 +115,7 @@ public interface IPipelineClient /// /// GitLabCollectionResponse GetBridgesAsync(PipelineBridgeQuery query); + + Task RetryAsync(int pipelineId, CancellationToken cancellationToken = default); } } diff --git a/NGitLab/Impl/PipelineClient.cs b/NGitLab/Impl/PipelineClient.cs index aa9743dc..6f9305ac 100644 --- a/NGitLab/Impl/PipelineClient.cs +++ b/NGitLab/Impl/PipelineClient.cs @@ -209,5 +209,11 @@ private string CreateGetBridgesUrl(PipelineBridgeQuery query) url = Utils.AddParameter(url, "scope", query.Scope); return url; } + + public Task RetryAsync(int pipelineId, CancellationToken cancellationToken = default) + { + var url = $"{_pipelinesPath}/{pipelineId.ToStringInvariant()}/retry"; + return _api.Post().ToAsync(url, cancellationToken); + } } } diff --git a/NGitLab/PublicAPI.Unshipped.txt b/NGitLab/PublicAPI.Unshipped.txt index 75705c78..4f9b3455 100644 --- a/NGitLab/PublicAPI.Unshipped.txt +++ b/NGitLab/PublicAPI.Unshipped.txt @@ -685,6 +685,7 @@ NGitLab.Impl.PipelineClient.GetTestReportsSummary(int pipelineId) -> NGitLab.Mod NGitLab.Impl.PipelineClient.GetVariables(int pipelineId) -> System.Collections.Generic.IEnumerable NGitLab.Impl.PipelineClient.GetVariablesAsync(int pipelineId) -> NGitLab.GitLabCollectionResponse NGitLab.Impl.PipelineClient.PipelineClient(NGitLab.Impl.API api, int projectId) -> void +NGitLab.Impl.PipelineClient.RetryAsync(int pipelineId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task NGitLab.Impl.PipelineClient.Search(NGitLab.Models.PipelineQuery query) -> System.Collections.Generic.IEnumerable NGitLab.Impl.PipelineClient.SearchAsync(NGitLab.Models.PipelineQuery query) -> NGitLab.GitLabCollectionResponse NGitLab.Impl.PipelineClient.this[int id].get -> NGitLab.Models.Pipeline @@ -857,6 +858,7 @@ NGitLab.IPipelineClient.GetTestReports(int pipelineId) -> NGitLab.Models.TestRep NGitLab.IPipelineClient.GetTestReportsSummary(int pipelineId) -> NGitLab.Models.TestReportSummary NGitLab.IPipelineClient.GetVariables(int pipelineId) -> System.Collections.Generic.IEnumerable NGitLab.IPipelineClient.GetVariablesAsync(int pipelineId) -> NGitLab.GitLabCollectionResponse +NGitLab.IPipelineClient.RetryAsync(int pipelineId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task NGitLab.IPipelineClient.Search(NGitLab.Models.PipelineQuery query) -> System.Collections.Generic.IEnumerable NGitLab.IPipelineClient.SearchAsync(NGitLab.Models.PipelineQuery query) -> NGitLab.GitLabCollectionResponse NGitLab.IPipelineClient.this[int id].get -> NGitLab.Models.Pipeline