From 799322e8289f3cbb05b1928346cf53052fadd94b Mon Sep 17 00:00:00 2001 From: Michael Carlson Date: Mon, 30 Sep 2019 17:40:19 -0600 Subject: [PATCH 1/2] add support for multiple extension filters --- Octokit.Tests/Clients/SearchClientTests.cs | 23 ++++++++++++++++++--- Octokit/Models/Request/SearchCodeRequest.cs | 11 ++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index c7eef5793e..470f8e72fe 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -1802,7 +1802,7 @@ public void TestingTheExtensionQualifier() var connection = Substitute.For(); var client = new SearchClient(connection); var request = new SearchCodeRequest("something"); - request.Extension = "cs"; + request.Extensions.Add("cs"); client.SearchCode(request); @@ -1811,6 +1811,22 @@ public void TestingTheExtensionQualifier() Arg.Is>(d => d["q"] == "something+extension:cs")); } + [Fact] + public void TestingTheExtensionQualifier_Multiple() + { + var connection = Substitute.For(); + var client = new SearchClient(connection); + var request = new SearchCodeRequest("something"); + request.Extensions.Add("cs"); + request.Extensions.Add("lol"); + + client.SearchCode(request); + + connection.Received().Get( + Arg.Is(u => u.ToString() == "search/code"), + Arg.Is>(d => d["q"] == "something+extension:cs+extension:lol")); + } + [Fact] public void TestingTheFileNameQualifier() { @@ -1877,14 +1893,15 @@ public void TestingTheRepoAndPathAndExtensionQualifiers() var client = new SearchClient(connection); var request = new SearchCodeRequest("something", "octokit", "octokit.net"); request.Path = "tools/FAKE.core"; - request.Extension = "fs"; + request.Extensions.Add("fs"); + request.Extensions.Add("cs"); client.SearchCode(request); connection.Received().Get( Arg.Is(u => u.ToString() == "search/code"), Arg.Is>(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] diff --git a/Octokit/Models/Request/SearchCodeRequest.cs b/Octokit/Models/Request/SearchCodeRequest.cs index e281b48a80..84282c468f 100644 --- a/Octokit/Models/Request/SearchCodeRequest.cs +++ b/Octokit/Models/Request/SearchCodeRequest.cs @@ -116,12 +116,12 @@ public IEnumerable In public string Path { get; set; } /// - /// Matches files with a certain extension. + /// Matches files with a certain extensions. /// /// /// https://help.github.com/articles/searching-code#extension /// - public string Extension { get; set; } + public IList Extensions { get; set; } = new List(); /// /// Matches specific file names @@ -189,9 +189,12 @@ public override IReadOnlyList MergedQualifiers() 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()) From 22bdce4f8a036a2320b0d838d75f7ead8296dadc Mon Sep 17 00:00:00 2001 From: Michael Carlson Date: Tue, 1 Oct 2019 09:55:30 -0600 Subject: [PATCH 2/2] update documentation, use ienumerable instead of ilist --- Octokit.Tests/Clients/SearchClientTests.cs | 22 ++++++++++++--------- Octokit/Models/Request/SearchCodeRequest.cs | 2 +- docs/search.md | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 470f8e72fe..a7e03ec72c 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -1801,14 +1801,16 @@ public void TestingTheExtensionQualifier() { var connection = Substitute.For(); var client = new SearchClient(connection); - var request = new SearchCodeRequest("something"); - request.Extensions.Add("cs"); + var request = new SearchCodeRequest("something") + { + Extensions = new[] { "txt" } + }; client.SearchCode(request); connection.Received().Get( Arg.Is(u => u.ToString() == "search/code"), - Arg.Is>(d => d["q"] == "something+extension:cs")); + Arg.Is>(d => d["q"] == "something+extension:txt")); } [Fact] @@ -1816,9 +1818,10 @@ public void TestingTheExtensionQualifier_Multiple() { var connection = Substitute.For(); var client = new SearchClient(connection); - var request = new SearchCodeRequest("something"); - request.Extensions.Add("cs"); - request.Extensions.Add("lol"); + var request = new SearchCodeRequest("something") + { + Extensions = new[] { "cs", "lol" } + }; client.SearchCode(request); @@ -1891,10 +1894,11 @@ public void TestingTheRepoAndPathAndExtensionQualifiers() { var connection = Substitute.For(); 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.Extensions.Add("fs"); - request.Extensions.Add("cs"); client.SearchCode(request); diff --git a/Octokit/Models/Request/SearchCodeRequest.cs b/Octokit/Models/Request/SearchCodeRequest.cs index 84282c468f..22a92354a5 100644 --- a/Octokit/Models/Request/SearchCodeRequest.cs +++ b/Octokit/Models/Request/SearchCodeRequest.cs @@ -121,7 +121,7 @@ public IEnumerable In /// /// https://help.github.com/articles/searching-code#extension /// - public IList Extensions { get; set; } = new List(); + public IEnumerable Extensions { get; set; } = new List(); /// /// Matches specific file names diff --git a/docs/search.md b/docs/search.md index da259e6ca0..bead98bcb8 100644 --- a/docs/search.md +++ b/docs/search.md @@ -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",