Skip to content

Commit

Permalink
Be able to search Tags (#798)
Browse files Browse the repository at this point in the history
* Be able to search Tags

* Add unit test

* Add more unit test

---------

Co-authored-by: Jordan Samouh <jordan.samouh@ubisoft.com>
  • Loading branch information
jsamouh and Jordan Samouh authored Nov 20, 2024
1 parent 3fe06fe commit eaf13ff
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions NGitLab.Tests/TagTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,41 @@ public async Task Test_can_tag_a_project()
Assert.That(tagsClient.All.FirstOrDefault(x => string.Equals(x.Name, "v0.5", StringComparison.Ordinal)), Is.Null);
}

[NGitLabRetry]
[TestCase("^v0.5", 1)]
[TestCase("^v0", 2)]
[TestCase("^v1", 0)]
[TestCase("v1", 0)]
[TestCase("0.5$", 1)]
[TestCase("0\\.", 0)]
[TestCase(".5$", 1)]
[TestCase("\\.5$", 0)]
[TestCase(".[0-9]$", 0)]
public async Task SearchTags(string search, int expectedCount)
{
// Arrange
using var context = await GitLabTestContext.CreateAsync();
var project = context.CreateProject(initializeWithCommits: true);
var tagClient = context.Client.GetRepository(project.Id).Tags;

tagClient.Create(new TagCreate
{
Name = "v0.5",
Message = "Test message",
Ref = project.DefaultBranch,
});

tagClient.Create(new TagCreate
{
Name = "v0.6",
Message = "Test second message",
Ref = project.DefaultBranch,
});

var tagFetched = tagClient.GetAsync(new TagQuery { Search = search });
Assert.That(tagFetched.Count(), Is.EqualTo(expectedCount));
}

[NGitLabRetry]
[TestCase("v0.5", true)]
[TestCase("v0.6", false)]
Expand Down
1 change: 1 addition & 0 deletions NGitLab/Impl/TagClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public GitLabCollectionResponse<Tag> GetAsync(TagQuery query)
url = Utils.AddParameter(url, "order_by", query.OrderBy);
url = Utils.AddParameter(url, "sort", query.Sort);
url = Utils.AddParameter(url, "per_page", query.PerPage);
url = Utils.AddParameter(url, "search", query.Search);
}

return _api.Get().GetAllAsync<Tag>(url);
Expand Down
2 changes: 2 additions & 0 deletions NGitLab/Models/TagQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class TagQuery
public string Sort { get; set; }

public int? PerPage { get; set; }

public string Search { get; set; }
}
2 changes: 2 additions & 0 deletions NGitLab/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3812,6 +3812,8 @@ NGitLab.Models.TagQuery.OrderBy.get -> string
NGitLab.Models.TagQuery.OrderBy.set -> void
NGitLab.Models.TagQuery.PerPage.get -> int?
NGitLab.Models.TagQuery.PerPage.set -> void
NGitLab.Models.TagQuery.Search.get -> string
NGitLab.Models.TagQuery.Search.set -> void
NGitLab.Models.TagQuery.Sort.get -> string
NGitLab.Models.TagQuery.Sort.set -> void
NGitLab.Models.TagQuery.TagQuery() -> void
Expand Down

0 comments on commit eaf13ff

Please sign in to comment.