mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
add support for multiple extension filters (#2019)
* add support for multiple extension filters * update documentation, use ienumerable instead of ilist
This commit is contained in:
committed by
Brendan Forster
parent
ce5ea64428
commit
3e7c70cf4e
@@ -1801,14 +1801,33 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchCodeRequest("something");
|
||||
request.Extension = "cs";
|
||||
var request = new SearchCodeRequest("something")
|
||||
{
|
||||
Extensions = new[] { "txt" }
|
||||
};
|
||||
|
||||
client.SearchCode(request);
|
||||
|
||||
connection.Received().Get<SearchCodeResult>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "search/code"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+extension:cs"));
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+extension:txt"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheExtensionQualifier_Multiple()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchCodeRequest("something")
|
||||
{
|
||||
Extensions = new[] { "cs", "lol" }
|
||||
};
|
||||
|
||||
client.SearchCode(request);
|
||||
|
||||
connection.Received().Get<SearchCodeResult>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "search/code"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+extension:cs+extension:lol"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1875,16 +1894,18 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchCodeRequest("something", "octokit", "octokit.net");
|
||||
var request = new SearchCodeRequest("something", "octokit", "octokit.net")
|
||||
{
|
||||
Extensions = new[] { "fs", "cs" }
|
||||
};
|
||||
request.Path = "tools/FAKE.core";
|
||||
request.Extension = "fs";
|
||||
|
||||
client.SearchCode(request);
|
||||
|
||||
connection.Received().Get<SearchCodeResult>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "search/code"),
|
||||
Arg.Is<Dictionary<string, string>>(d =>
|
||||
d["q"] == "something+path:tools/FAKE.core+extension:fs+repo:octokit/octokit.net"));
|
||||
d["q"] == "something+path:tools/FAKE.core+extension:fs+extension:cs+repo:octokit/octokit.net"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -116,12 +116,12 @@ namespace Octokit
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Matches files with a certain extension.
|
||||
/// Matches files with a certain extensions.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://help.github.com/articles/searching-code#extension
|
||||
/// </remarks>
|
||||
public string Extension { get; set; }
|
||||
public IEnumerable<string> Extensions { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Matches specific file names
|
||||
@@ -189,9 +189,12 @@ namespace Octokit
|
||||
parameters.Add(string.Format(CultureInfo.InvariantCulture, "path:{0}", Path));
|
||||
}
|
||||
|
||||
if (Extension.IsNotBlank())
|
||||
if (Extensions.Any())
|
||||
{
|
||||
parameters.Add(string.Format(CultureInfo.InvariantCulture, "extension:{0}", Extension));
|
||||
foreach (var extension in Extensions)
|
||||
{
|
||||
parameters.Add(string.Format(CultureInfo.InvariantCulture, "extension:{0}", extension));
|
||||
}
|
||||
}
|
||||
|
||||
if (FileName.IsNotBlank())
|
||||
|
||||
@@ -212,7 +212,7 @@ var request = new SearchCodeRequest("auth")
|
||||
Path = "app/assets",
|
||||
|
||||
// we may want to restrict the file based on file extension
|
||||
Extension = "json",
|
||||
Extensions = new[] { "json", "sql" },
|
||||
|
||||
// restrict search to a specific file name
|
||||
FileName = "app.json",
|
||||
|
||||
Reference in New Issue
Block a user