Skip to content

Commit cc33e8a

Browse files
committed
fix: issue search in
1 parent bbd0741 commit cc33e8a

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

src/GitLabApiClient/Internal/Queries/IssuesQueryBuilder.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ protected override void BuildCore(Query query, IssuesQueryOptions options)
4444
if (!options.Filter.IsNullOrEmpty())
4545
query.Add("search", options.Filter);
4646

47+
if (options.In != SearchIn.TitleAndDescription)
48+
query.Add("in", GetSearchInQueryValue(options.In));
49+
4750
if (options.IsConfidential)
4851
query.Add("confidential", true);
4952

@@ -87,5 +90,20 @@ private static string GetIssuesOrderQueryValue(IssuesOrder order)
8790
throw new NotSupportedException($"Order {order} is not supported");
8891
}
8992
}
93+
94+
private static string GetSearchInQueryValue(SearchIn searchIn)
95+
{
96+
switch (searchIn)
97+
{
98+
case SearchIn.Title:
99+
return "title";
100+
case SearchIn.Description:
101+
return "description";
102+
case SearchIn.TitleAndDescription:
103+
return "title,description";
104+
default:
105+
throw new NotSupportedException($"SearchIn {searchIn} is not supported");
106+
}
107+
}
90108
}
91109
}

src/GitLabApiClient/Models/Issues/Requests/IssuesQueryOptions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal IssuesQueryOptions() { }
1818
public IssueState State { get; set; }
1919

2020
/// <summary>
21-
/// List of label names, issues must have all labels to be returned.
21+
/// List of label names, issues must have all labels to be returned.
2222
/// No+Label lists all issues with no labels.
2323
/// </summary>
2424
public IList<string> Labels { get; set; } = new List<string>();
@@ -75,6 +75,11 @@ internal IssuesQueryOptions() { }
7575
/// </summary>
7676
public string Filter { get; set; }
7777

78+
/// <summary>
79+
/// Modify the scope of the search attribute. Title, Description, or TitleAndDescription. Default is TitleAndDescription
80+
/// </summary>
81+
public SearchIn In { get; set; }
82+
7883
/// <summary>
7984
/// Return issues created after the given time (inclusive)
8085
/// </summary>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace GitLabApiClient.Models.Issues.Requests
2+
{
3+
public enum SearchIn
4+
{
5+
TitleAndDescription,
6+
Title,
7+
Description,
8+
}
9+
}

test/GitLabApiClient.Test/Internal/Queries/IssuesQueryBuilderTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void NonDefaultQueryBuilt()
3030
Order = IssuesOrder.UpdatedAt,
3131
SortOrder = SortOrder.Ascending,
3232
Filter = "filter",
33+
In = SearchIn.Description,
3334
CreatedAfter = new DateTime(1991, 11, 11, 1, 1, 1),
3435
CreatedBefore = new DateTime(1991, 12, 12, 2, 2, 2),
3536
UpdatedAfter = new DateTime(1991, 4, 4, 4, 4, 4),
@@ -50,6 +51,7 @@ public void NonDefaultQueryBuilt()
5051
"order_by=updated_at&" +
5152
"sort=asc&" +
5253
"search=filter&" +
54+
"in=description&" +
5355
"confidential=true&" +
5456
"created_before=1991-12-12T02%3a02%3a02.0000000&" +
5557
"created_after=1991-11-11T01%3a01%3a01.0000000&" +
@@ -76,6 +78,7 @@ public void NonDefaultQueryBuiltWithUserNames()
7678
Order = IssuesOrder.UpdatedAt,
7779
SortOrder = SortOrder.Ascending,
7880
Filter = "filter",
81+
In = SearchIn.Title,
7982
CreatedAfter = new DateTime(1991, 11, 11, 1, 1, 1),
8083
CreatedBefore = new DateTime(1991, 12, 12, 2, 2, 2),
8184
UpdatedAfter = new DateTime(1991, 4, 4, 4, 4, 4),
@@ -96,6 +99,7 @@ public void NonDefaultQueryBuiltWithUserNames()
9699
"order_by=updated_at&" +
97100
"sort=asc&" +
98101
"search=filter&" +
102+
"in=title&" +
99103
"confidential=true&" +
100104
"created_before=1991-12-12T02%3a02%3a02.0000000&" +
101105
"created_after=1991-11-11T01%3a01%3a01.0000000&" +

test/GitLabApiClient.Test/IssuesClientTest.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,49 @@ public async Task CreateIssueWithTasks()
190190
i.TaskCompletionStatus.Completed == 1 &&
191191
i.TimeStats != null);
192192
}
193+
194+
[Fact]
195+
public async Task CreatedIssueCanBeRetrievedByTitleOrDescription()
196+
{
197+
//arrange
198+
string title = Guid.NewGuid().ToString();
199+
string description = "Description";
200+
var issue = await _sut.CreateAsync(TestProjectTextId, new CreateIssueRequest(title)
201+
{
202+
Description = description
203+
});
204+
205+
//act
206+
var issueSearchedInTitle = (await _sut.GetAllAsync(TestProjectTextId, options: o =>
207+
{
208+
o.In = SearchIn.Title;
209+
o.Filter = title;
210+
}))
211+
.FirstOrDefault();
212+
213+
var issueSearchedInDescription = (await _sut.GetAllAsync(TestProjectTextId, options: o =>
214+
{
215+
o.In = SearchIn.Description;
216+
o.Filter = description;
217+
}))
218+
.FirstOrDefault();
219+
220+
var issueSearchedInTitleAndDescription = (await _sut.GetAllAsync(TestProjectTextId, options: o =>
221+
{
222+
o.In = SearchIn.TitleAndDescription;
223+
o.Filter = description;
224+
}))
225+
.FirstOrDefault();
226+
227+
//assert
228+
issue.Should().Match<Issue>(i =>
229+
i.ProjectId == TestProjectTextId &&
230+
i.Title == title &&
231+
i.Description == description);
232+
233+
issueSearchedInTitle.Should().BeEquivalentTo(issue, o => o.Excluding(s => s.UpdatedAt));
234+
issueSearchedInDescription.Should().BeEquivalentTo(issue, o => o.Excluding(s => s.UpdatedAt));
235+
issueSearchedInTitleAndDescription.Should().BeEquivalentTo(issue, o => o.Excluding(s => s.UpdatedAt));
236+
}
193237
}
194238
}

0 commit comments

Comments
 (0)