Skip to content

Commit

Permalink
Merge pull request #864 from fffej/add-filename-for-code-search
Browse files Browse the repository at this point in the history
add filename for code search
  • Loading branch information
haacked committed Sep 9, 2015
2 parents de212ef + 9634dd5 commit b858613
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Octokit.Tests.Integration/Clients/SearchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ public async Task SearchForFunctionInCode()
Assert.NotEmpty(repos.Items);
}

[Fact]
public async Task SearchForFileNameInCode()
{
var request = new SearchCodeRequest("swag")
{
FileName = "readme.md"
};

var repos = await _gitHubClient.Search.SearchCode(request);

Assert.NotEmpty(repos.Items);
}

[Fact]
public async Task SearchForWordInCode()
{
Expand Down
15 changes: 15 additions & 0 deletions Octokit.Tests/Clients/SearchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,21 @@ public void TestingTheExtensionQualifier()
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+extension:cs"));
}

[Fact]
public void TestingTheFileNameQualifier()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchCodeRequest("something");
request.FileName = "packages.config";

client.SearchCode(request);

connection.Received().Get<SearchCodeResult>(
Arg.Is<Uri>(u => u.ToString() == "search/code"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+filename:packages.config"));
}

[Fact]
public void TestingTheUserQualifier()
{
Expand Down
13 changes: 13 additions & 0 deletions Octokit/Models/Request/SearchCodeRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ public IEnumerable<CodeInQualifier> In
/// </remarks>
public string Extension { get; set; }

/// <summary>
/// Matches specific file names
/// </summary>
/// <remarks>
/// https://help.github.com/articles/searching-code/#search-by-filename
/// </remarks>
public string FileName { get; set; }

/// <summary>
/// Limits searches to a specific user.
/// </summary>
Expand Down Expand Up @@ -161,6 +169,11 @@ public override IReadOnlyList<string> MergedQualifiers()
parameters.Add(String.Format(CultureInfo.InvariantCulture, "extension:{0}", Extension));
}

if (FileName.IsNotBlank())
{
parameters.Add(String.Format(CultureInfo.InvariantCulture, "filename:{0}", FileName));
}

if (User.IsNotBlank())
{
parameters.Add(String.Format(CultureInfo.InvariantCulture, "user:{0}", User));
Expand Down

0 comments on commit b858613

Please sign in to comment.