Skip to content

Commit

Permalink
Fix adding the wrong scope parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjhzjxc authored and meziantou committed Dec 18, 2023
1 parent 0b94429 commit 61f6387
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
20 changes: 20 additions & 0 deletions NGitLab.Tests/PipelineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ public async Task Test_can_list_all_jobs_from_project()
Assert.That(allJobs.Any());
}

[Test]
[NGitLabRetry]
public async Task Test_can_list_jobs_from_pipeline()
{
using var context = await GitLabTestContext.CreateAsync();
var project = context.CreateProject();
var pipelineClient = context.Client.GetPipelines(project.Id);
JobTests.AddGitLabCiFile(context.Client, project);

var pipelines = await GitLabTestContext.RetryUntilAsync(() => pipelineClient.All, p => p.Any(), TimeSpan.FromSeconds(120));
var pipeline = pipelines.First();

var pipelineJobQuery = new PipelineJobQuery
{
PipelineId = pipeline.Id, Scope = new[] { "success", "pending" },
};
var allJobs = await GitLabTestContext.RetryUntilAsync(() => pipelineClient.GetJobsAsync(pipelineJobQuery).ToList(), p => p.Any(), TimeSpan.FromSeconds(120));
Assert.That(allJobs.Any());
}

[Test]
[NGitLabRetry]
public async Task Test_search_for_pipeline()
Expand Down
4 changes: 2 additions & 2 deletions NGitLab/Impl/PipelineClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public GitLabCollectionResponse<Job> GetJobsAsync(PipelineJobQuery query)
private string CreateGetJobsUrl(PipelineJobQuery query)
{
var url = $"{_pipelinesPath}/{query.PipelineId.ToStringInvariant()}/jobs";
url = Utils.AddParameter(url, "scope", query.Scope);
url = Utils.AddArrayParameter(url, "scope", query.Scope);
url = Utils.AddParameter(url, "include_retried", query.IncludeRetried);
return url;
}
Expand Down Expand Up @@ -213,7 +213,7 @@ public GitLabCollectionResponse<Bridge> GetBridgesAsync(PipelineBridgeQuery quer
private string CreateGetBridgesUrl(PipelineBridgeQuery query)
{
var url = $"{_pipelinesPath}/{query.PipelineId.ToStringInvariant()}/bridges";
url = Utils.AddParameter(url, "scope", query.Scope);
url = Utils.AddArrayParameter(url, "scope", query.Scope);
return url;
}

Expand Down
15 changes: 15 additions & 0 deletions NGitLab/Impl/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ public static string AddParameter(string url, string parameterName, int[] values
return Equals(values, null) ? url : AddParameterInternal(url, parameterName, string.Join(",", values));
}

public static string AddArrayParameter(string url, string parameterName, string[] values)
{
if (Equals(values, null))
{
return url;
}

foreach (var value in values)
{
url = AddParameterInternal(url, $"{parameterName}[]", value);
}

return url;
}

public static string AddOrderBy(string url, string orderBy = null, bool supportKeysetPagination = true)
{
if (supportKeysetPagination && (string.IsNullOrEmpty(orderBy) || string.Equals(orderBy, "id", StringComparison.Ordinal)))
Expand Down

0 comments on commit 61f6387

Please sign in to comment.