From f05f6dcab9ffed84570a6e5e49d1b3f1851d484d Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Fri, 3 Jun 2016 00:39:55 -0700 Subject: [PATCH] Add support for code searches without a search term (#1338) --- .../Clients/SearchClientTests.cs | 14 ++++++++++++++ Octokit/Models/Request/BaseSearchRequest.cs | 9 ++++++++- Octokit/Models/Request/SearchCodeRequest.cs | 8 ++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index 8ae982509e..b1267410cc 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -57,6 +57,20 @@ public async Task SearchForFileNameInCode() Assert.NotEmpty(repos.Items); } + [IntegrationTest] + public async Task SearchForFileNameInCodeWithoutTerm() + { + var request = new SearchCodeRequest() + { + FileName = "readme.md", + Repos = new RepositoryCollection { "octokit/octokit.net" } + }; + + var repos = await _gitHubClient.Search.SearchCode(request); + + Assert.NotEmpty(repos.Items); + } + [IntegrationTest] public async Task SearchForWordInCode() { diff --git a/Octokit/Models/Request/BaseSearchRequest.cs b/Octokit/Models/Request/BaseSearchRequest.cs index d3cff73d0c..7ff689def8 100644 --- a/Octokit/Models/Request/BaseSearchRequest.cs +++ b/Octokit/Models/Request/BaseSearchRequest.cs @@ -85,7 +85,14 @@ private string TermAndQualifiers get { var mergedParameters = string.Join("+", MergedQualifiers()); - return Term + (mergedParameters.IsNotBlank() ? "+" + mergedParameters : ""); + if (string.IsNullOrEmpty(Term)) + { + return mergedParameters; + } + else + { + return Term + (mergedParameters.IsNotBlank() ? "+" + mergedParameters : ""); + } } } diff --git a/Octokit/Models/Request/SearchCodeRequest.cs b/Octokit/Models/Request/SearchCodeRequest.cs index f5c8693dc9..4e4142310f 100644 --- a/Octokit/Models/Request/SearchCodeRequest.cs +++ b/Octokit/Models/Request/SearchCodeRequest.cs @@ -15,6 +15,14 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class SearchCodeRequest : BaseSearchRequest { + /// + /// Initializes a new instance of the class. + /// + public SearchCodeRequest() : base() + { + Repos = new RepositoryCollection(); + } + /// /// Initializes a new instance of the class. ///