forked from octokit/octokit.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-search-issues.linq
60 lines (51 loc) · 1.9 KB
/
10-search-issues.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<Query Kind="Program">
<NuGetReference>Octokit</NuGetReference>
<NuGetReference>Octokit.Reactive</NuGetReference>
<Namespace>Octokit</Namespace>
<Namespace>Octokit.Reactive</Namespace>
<Namespace>System</Namespace>
<Namespace>System.Reactive.Linq</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
async Task Main(string[] args)
{
var owner = string.Empty;
var reponame = string.Empty;
//Search Issues with xamarin keyword and get the results
GitHubClient client = new GitHubClient(
new Octokit.ProductHeaderValue("Octokit.samples"));
owner = "octokit";
reponame = "octokit.net";
// or if you don't want to give an app your creds
// you can use a token from an OAuth app
// Here is the URL to get tokens https://github.com/settings/tokens
// and save the token using Util.SetPassword("github","CHANGETHIS")
client.Credentials = new Credentials(Util.GetPassword("github"));
var issue = new SearchIssuesRequest("xamarin");
issue.Repos.Add(owner,reponame);
issue.SortField = IssueSearchSort.Updated;
var searchresults = await client.Search.SearchIssues(issue);
//For every issue get the comments for it
var commentsclient = client.Issue.Comment;
var comments = searchresults.Items.Select(async i =>
new { IssueNumber = i.Number,
Comments = await commentsclient
.GetAllForIssue(owner, reponame, i.Number)});
var issueComments = await Task.WhenAll( comments);
//Combine the comments with Issue and then dump it.
searchresults.Items.Select(i => new
{
Number = Util.RawHtml(new XElement("a",
new XAttribute("href", i.HtmlUrl.ToString()), i.Number)),
i.Title,
i.Body,
i.State,
Comments = issueComments.FirstOrDefault(c => c.IssueNumber == i.Number)
.Comments.Select(c =>
new { User = c.User.Id,
Name = c.User.Login,
Content = c.Body,
Date = c.CreatedAt,
Id = c.Id, c.Body})
} ).Dump();
}