Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add filename for code search #864

Merged
merged 2 commits into from
Sep 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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