From eaf13ff8f93847e5c96d069741879a4d1198624a Mon Sep 17 00:00:00 2001 From: Jordan Samouh <616999+jsamouh@users.noreply.github.com> Date: Wed, 20 Nov 2024 09:10:38 -0500 Subject: [PATCH] Be able to search Tags (#798) * Be able to search Tags * Add unit test * Add more unit test --------- Co-authored-by: Jordan Samouh --- NGitLab.Tests/TagTests.cs | 35 +++++++++++++++++++++++++++++++++ NGitLab/Impl/TagClient.cs | 1 + NGitLab/Models/TagQuery.cs | 2 ++ NGitLab/PublicAPI.Unshipped.txt | 2 ++ 4 files changed, 40 insertions(+) diff --git a/NGitLab.Tests/TagTests.cs b/NGitLab.Tests/TagTests.cs index 31e729de..cc12c450 100644 --- a/NGitLab.Tests/TagTests.cs +++ b/NGitLab.Tests/TagTests.cs @@ -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)] diff --git a/NGitLab/Impl/TagClient.cs b/NGitLab/Impl/TagClient.cs index 9dad52fa..be2b095c 100644 --- a/NGitLab/Impl/TagClient.cs +++ b/NGitLab/Impl/TagClient.cs @@ -43,6 +43,7 @@ public GitLabCollectionResponse 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(url); diff --git a/NGitLab/Models/TagQuery.cs b/NGitLab/Models/TagQuery.cs index 31a26e8a..1be0fa8b 100644 --- a/NGitLab/Models/TagQuery.cs +++ b/NGitLab/Models/TagQuery.cs @@ -7,4 +7,6 @@ public class TagQuery public string Sort { get; set; } public int? PerPage { get; set; } + + public string Search { get; set; } } diff --git a/NGitLab/PublicAPI.Unshipped.txt b/NGitLab/PublicAPI.Unshipped.txt index a9dbce1f..2b2145e2 100644 --- a/NGitLab/PublicAPI.Unshipped.txt +++ b/NGitLab/PublicAPI.Unshipped.txt @@ -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