Skip to content

fix: issue search in #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/GitLabApiClient/Internal/Queries/IssuesQueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ protected override void BuildCore(Query query, IssuesQueryOptions options)
if (!options.Filter.IsNullOrEmpty())
query.Add("search", options.Filter);

if (options.In != SearchIn.TitleAndDescription)
query.Add("in", GetSearchInQueryValue(options.In));

if (options.IsConfidential)
query.Add("confidential", true);

Expand Down Expand Up @@ -87,5 +90,20 @@ private static string GetIssuesOrderQueryValue(IssuesOrder order)
throw new NotSupportedException($"Order {order} is not supported");
}
}

private static string GetSearchInQueryValue(SearchIn searchIn)
{
switch (searchIn)
{
case SearchIn.Title:
return "title";
case SearchIn.Description:
return "description";
case SearchIn.TitleAndDescription:
return "title,description";
default:
throw new NotSupportedException($"SearchIn {searchIn} is not supported");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal IssuesQueryOptions() { }
public IssueState State { get; set; }

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

/// <summary>
/// Modify the scope of the search attribute. Title, Description, or TitleAndDescription. Default is TitleAndDescription
/// </summary>
public SearchIn In { get; set; }

/// <summary>
/// Return issues created after the given time (inclusive)
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/GitLabApiClient/Models/Issues/Requests/SearchIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GitLabApiClient.Models.Issues.Requests
{
public enum SearchIn
{
TitleAndDescription,
Title,
Description,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void NonDefaultQueryBuilt()
Order = IssuesOrder.UpdatedAt,
SortOrder = SortOrder.Ascending,
Filter = "filter",
In = SearchIn.Description,
CreatedAfter = new DateTime(1991, 11, 11, 1, 1, 1),
CreatedBefore = new DateTime(1991, 12, 12, 2, 2, 2),
UpdatedAfter = new DateTime(1991, 4, 4, 4, 4, 4),
Expand All @@ -50,6 +51,7 @@ public void NonDefaultQueryBuilt()
"order_by=updated_at&" +
"sort=asc&" +
"search=filter&" +
"in=description&" +
"confidential=true&" +
"created_before=1991-12-12T02%3a02%3a02.0000000&" +
"created_after=1991-11-11T01%3a01%3a01.0000000&" +
Expand All @@ -76,6 +78,7 @@ public void NonDefaultQueryBuiltWithUserNames()
Order = IssuesOrder.UpdatedAt,
SortOrder = SortOrder.Ascending,
Filter = "filter",
In = SearchIn.Title,
CreatedAfter = new DateTime(1991, 11, 11, 1, 1, 1),
CreatedBefore = new DateTime(1991, 12, 12, 2, 2, 2),
UpdatedAfter = new DateTime(1991, 4, 4, 4, 4, 4),
Expand All @@ -96,6 +99,7 @@ public void NonDefaultQueryBuiltWithUserNames()
"order_by=updated_at&" +
"sort=asc&" +
"search=filter&" +
"in=title&" +
"confidential=true&" +
"created_before=1991-12-12T02%3a02%3a02.0000000&" +
"created_after=1991-11-11T01%3a01%3a01.0000000&" +
Expand Down
44 changes: 44 additions & 0 deletions test/GitLabApiClient.Test/IssuesClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,49 @@ public async Task CreateIssueWithTasks()
i.TaskCompletionStatus.Completed == 1 &&
i.TimeStats != null);
}

[Fact]
public async Task CreatedIssueCanBeRetrievedByTitleOrDescription()
{
//arrange
string title = Guid.NewGuid().ToString();
string description = "Description";
var issue = await _sut.CreateAsync(TestProjectTextId, new CreateIssueRequest(title)
{
Description = description
});

//act
var issueSearchedInTitle = (await _sut.GetAllAsync(TestProjectTextId, options: o =>
{
o.In = SearchIn.Title;
o.Filter = title;
}))
.FirstOrDefault();

var issueSearchedInDescription = (await _sut.GetAllAsync(TestProjectTextId, options: o =>
{
o.In = SearchIn.Description;
o.Filter = description;
}))
.FirstOrDefault();

var issueSearchedInTitleAndDescription = (await _sut.GetAllAsync(TestProjectTextId, options: o =>
{
o.In = SearchIn.TitleAndDescription;
o.Filter = description;
}))
.FirstOrDefault();

//assert
issue.Should().Match<Issue>(i =>
i.ProjectId == TestProjectTextId &&
i.Title == title &&
i.Description == description);

issueSearchedInTitle.Should().BeEquivalentTo(issue, o => o.Excluding(s => s.UpdatedAt));
issueSearchedInDescription.Should().BeEquivalentTo(issue, o => o.Excluding(s => s.UpdatedAt));
issueSearchedInTitleAndDescription.Should().BeEquivalentTo(issue, o => o.Excluding(s => s.UpdatedAt));
}
}
}