Skip to content

Commit 8663861

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

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-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+
Title,
6+
Description,
7+
TitleAndDescription
8+
}
9+
}

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)