From d1bd50cdf3b3efb8e45cb092bfed5632081d1c35 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sun, 19 Jul 2015 08:39:31 +0930 Subject: [PATCH] wrote some examples --- docs/search.md | 99 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 84 insertions(+), 15 deletions(-) diff --git a/docs/search.md b/docs/search.md index 58ef1bbe88..4024f79bd5 100644 --- a/docs/search.md +++ b/docs/search.md @@ -8,36 +8,73 @@ on the GitHub or GitHub Enterprise server: - code - users -I won't go into the full details here as the [developer documentation](https://developer.github.com/) -covers all the options far better than I could. - ## Search Issues -You can search for issues containing a given phrase across many repositories: +You can search for issues containing a given phrase across many +repositories: ```csharp -// a search -var request = new SearchIssuesRequest("linux"); +// searching without specifying a term +var request = new SearchIssuesRequest(); + +// you should focus your search to a specific repo +request.Repos.Add("aspnet/dnx"); -// it is highly recommended to search in specific repositories +// or use a series of repositories request.Repos = new Collection { "aspnet/dnx", "aspnet/dnvm" }; +``` -// other parameters available for tweaking the output -request.SortField = IssueSearchSort.Created; -request.Order = SortDirection.Descending; +There's many other options available here to tweak +your search criteria: + +```csharp +// if you're searching for a specific term, you can +// focus your search on specific criteria +request.In = new[] { + IssueInQualifier.Title, + IssueInQualifier.Body +}; + +// you can restrict your search to issues or pull requests +request.Type = IssueTypeQualifier.Issue; + +// you can filter on when the issue was created or updated +var aWeekAgo = DateTime.Now.Subtract(TimeSpan.FromDays(7)); +request.Created = new DateRange(aWeekAgo, SearchQualifierOperator.GreaterThan) + +// you can search for issues created by, assigned to +// or mentioning a specific user +request.Author = "davidfowl"; +request.Assignee = "damianedwards"; +request.Mentions = "shiftkey"; +request.Commenter = "haacked"; + +// rather than setting all these, you can use this to find +// all the above for a specific user with this one-liner +request.Involves = "davidfowl"; + +// by default this will search on open issues, set this if +// you want to get all issues +request.State = ItemState.All; +// or to just search closed issues +request.State = ItemState.Closed; ``` -By default, search will return the first page of results and use -a page size of 100 results. +And there's other options available for how the results are returned: ```csharp -request.Page = 2; +request.SortField = IssueSearchSort.Created; +request.Order = SortDirection.Descending; + +// 100 results per page as default request.PerPage = 30; -``` +// execute this when you want to fetch multiple pages +request.Page = 2; +``` Once you've set the right parameters, execute the request: @@ -47,11 +84,43 @@ var repos = await client.Search.SearchIssues(request); Console.WriteLine("Query has {0} matches.", repos.TotalCount); Console.WriteLine("Response has {0} items.", repos.Items.Count); -Assert.NotEmpty(); ``` +## Search Pull Requests + +Another scenario to consider is how to search broadly: + +```csharp +var threeMonthsAgoIsh = DateTime.Now.Subtract(TimeSpan.FromDays(90)); + +// search for a specific term +var request = new SearchIssuesRequest("linux") +{ + // only search pull requests + Type = IssueTypeQualifier.PR, + + // search across open and closed PRs + State = ItemState.All, + + // search repositories which contain code + // matching a given language + Language = Language.CSharp, + + // focus on pull requests updated recently + Updated = new DateRange(threeMonthsAgoIsh, SearchQualifierOperator.GreaterThan) +}; +``` + + + ## Search Repositories +**TODO** + ## Search Code +**TODO** + ## Search Users + +**TODO**