diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index c7eef5793e..a7e03ec72c 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -1801,14 +1801,33 @@ public void TestingTheExtensionQualifier() { var connection = Substitute.For(); 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( + Arg.Is(u => u.ToString() == "search/code"), + Arg.Is>(d => d["q"] == "something+extension:txt")); + } + + [Fact] + public void TestingTheExtensionQualifier_Multiple() + { + var connection = Substitute.For(); + var client = new SearchClient(connection); + var request = new SearchCodeRequest("something") + { + Extensions = new[] { "cs", "lol" } + }; 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:cs+extension:lol")); } [Fact] @@ -1875,16 +1894,18 @@ 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.Extension = "fs"; 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..22a92354a5 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 IEnumerable 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()) 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",