forked from dotnet/samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
27 lines (23 loc) · 1.01 KB
/
Program.cs
File metadata and controls
27 lines (23 loc) · 1.01 KB
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
using System.Net.Http.Headers;
using System.Net.Http.Json;
using HttpClient client = new();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json"));
client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");
var repositories = await ProcessRepositoriesAsync(client);
foreach (var repo in repositories)
{
Console.WriteLine($"Name: {repo.Name}");
Console.WriteLine($"Homepage: {repo.Homepage}");
Console.WriteLine($"GitHub: {repo.GitHubHomeUrl}");
Console.WriteLine($"Description: {repo.Description}");
Console.WriteLine($"Watchers: {repo.Watchers:#,0}");
Console.WriteLine($"{repo.LastPush}");
Console.WriteLine();
}
static async Task<List<Repository>> ProcessRepositoriesAsync(HttpClient client)
{
var repositories = await client.GetFromJsonAsync<List<Repository>>("https://api.github.com/orgs/dotnet/repos");
return repositories ?? new List<Repository>();
}