Skip to content

Commit eaf13ff

Browse files
jsamouhJordan Samouh
andauthored
Be able to search Tags (#798)
* Be able to search Tags * Add unit test * Add more unit test --------- Co-authored-by: Jordan Samouh <jordan.samouh@ubisoft.com>
1 parent 3fe06fe commit eaf13ff

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

NGitLab.Tests/TagTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,41 @@ public async Task Test_can_tag_a_project()
3333
Assert.That(tagsClient.All.FirstOrDefault(x => string.Equals(x.Name, "v0.5", StringComparison.Ordinal)), Is.Null);
3434
}
3535

36+
[NGitLabRetry]
37+
[TestCase("^v0.5", 1)]
38+
[TestCase("^v0", 2)]
39+
[TestCase("^v1", 0)]
40+
[TestCase("v1", 0)]
41+
[TestCase("0.5$", 1)]
42+
[TestCase("0\\.", 0)]
43+
[TestCase(".5$", 1)]
44+
[TestCase("\\.5$", 0)]
45+
[TestCase(".[0-9]$", 0)]
46+
public async Task SearchTags(string search, int expectedCount)
47+
{
48+
// Arrange
49+
using var context = await GitLabTestContext.CreateAsync();
50+
var project = context.CreateProject(initializeWithCommits: true);
51+
var tagClient = context.Client.GetRepository(project.Id).Tags;
52+
53+
tagClient.Create(new TagCreate
54+
{
55+
Name = "v0.5",
56+
Message = "Test message",
57+
Ref = project.DefaultBranch,
58+
});
59+
60+
tagClient.Create(new TagCreate
61+
{
62+
Name = "v0.6",
63+
Message = "Test second message",
64+
Ref = project.DefaultBranch,
65+
});
66+
67+
var tagFetched = tagClient.GetAsync(new TagQuery { Search = search });
68+
Assert.That(tagFetched.Count(), Is.EqualTo(expectedCount));
69+
}
70+
3671
[NGitLabRetry]
3772
[TestCase("v0.5", true)]
3873
[TestCase("v0.6", false)]

NGitLab/Impl/TagClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public GitLabCollectionResponse<Tag> GetAsync(TagQuery query)
4343
url = Utils.AddParameter(url, "order_by", query.OrderBy);
4444
url = Utils.AddParameter(url, "sort", query.Sort);
4545
url = Utils.AddParameter(url, "per_page", query.PerPage);
46+
url = Utils.AddParameter(url, "search", query.Search);
4647
}
4748

4849
return _api.Get().GetAllAsync<Tag>(url);

NGitLab/Models/TagQuery.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ public class TagQuery
77
public string Sort { get; set; }
88

99
public int? PerPage { get; set; }
10+
11+
public string Search { get; set; }
1012
}

NGitLab/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,6 +3812,8 @@ NGitLab.Models.TagQuery.OrderBy.get -> string
38123812
NGitLab.Models.TagQuery.OrderBy.set -> void
38133813
NGitLab.Models.TagQuery.PerPage.get -> int?
38143814
NGitLab.Models.TagQuery.PerPage.set -> void
3815+
NGitLab.Models.TagQuery.Search.get -> string
3816+
NGitLab.Models.TagQuery.Search.set -> void
38153817
NGitLab.Models.TagQuery.Sort.get -> string
38163818
NGitLab.Models.TagQuery.Sort.set -> void
38173819
NGitLab.Models.TagQuery.TagQuery() -> void

0 commit comments

Comments
 (0)