Skip to content

Commit 8229855

Browse files
committed
feat: Add open pull request details
1 parent 8b71948 commit 8229855

File tree

4 files changed

+86
-4
lines changed

4 files changed

+86
-4
lines changed

GitHub/GraphPullRequest.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
3+
namespace Open_Rails_Code_Bot.GitHub
4+
{
5+
class GraphPullRequest
6+
{
7+
public Uri Url;
8+
public int Number;
9+
public string Title;
10+
public DateTimeOffset CreatedAt;
11+
public GraphPullRequestAuthor Author;
12+
public GraphPullRequestRef HeadRef;
13+
public GraphPullRequestLabels Labels;
14+
}
15+
16+
class GraphPullRequestAuthor
17+
{
18+
public Uri Url;
19+
public string Login;
20+
}
21+
22+
class GraphPullRequestRef
23+
{
24+
public string Prefix;
25+
public string Name;
26+
}
27+
28+
class GraphPullRequestLabels
29+
{
30+
public GraphPullRequestLabelNode[] Nodes;
31+
}
32+
33+
class GraphPullRequestLabelNode
34+
{
35+
public string Name;
36+
}
37+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Open_Rails_Code_Bot.GitHub
44
{
5-
class GraphOrganizationTeamMember
5+
class GraphTeamMember
66
{
77
public Uri Url;
88
public string Login;

GitHub/Query.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal async Task<JObject> Get(string query)
3535
return JObject.Parse(text);
3636
}
3737

38-
public async Task<IReadOnlyList<GraphOrganizationTeamMember>> GetTeamMembers(string organization, string team)
38+
public async Task<IReadOnlyList<GraphTeamMember>> GetTeamMembers(string organization, string team)
3939
{
4040
var query = @"
4141
organization(login: """ + organization + @""") {
@@ -51,7 +51,40 @@ public async Task<IReadOnlyList<GraphOrganizationTeamMember>> GetTeamMembers(str
5151
}
5252
";
5353
var response = await Get(query);
54-
return response["data"]["organization"]["team"]["members"]["nodes"].ToObject<GraphOrganizationTeamMember[]>();
54+
return response["data"]["organization"]["team"]["members"]["nodes"].ToObject<GraphTeamMember[]>();
55+
}
56+
57+
public async Task<IReadOnlyList<GraphPullRequest>> GetOpenPullRequests(string organization, string repository)
58+
{
59+
var query = @"
60+
organization(login: """ + organization + @""") {
61+
repository(name: """ + repository + @""") {
62+
pullRequests(states: OPEN, first: 100, orderBy: {field: CREATED_AT, direction: ASC}) {
63+
nodes {
64+
url
65+
number
66+
title
67+
createdAt
68+
author {
69+
url
70+
login
71+
}
72+
headRef {
73+
prefix
74+
name
75+
}
76+
labels(first: 100) {
77+
nodes {
78+
name
79+
}
80+
}
81+
}
82+
}
83+
}
84+
}
85+
";
86+
var response = await Get(query);
87+
return response["data"]["organization"]["repository"]["pullRequests"]["nodes"].ToObject<GraphPullRequest[]>();
5588
}
5689
}
5790
}

Program.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Threading.Tasks;
45
using Microsoft.Extensions.Configuration;
56
using Open_Rails_Code_Bot.GitHub;
@@ -43,9 +44,20 @@ static async Task AsyncMain(IConfigurationRoot config)
4344

4445
var members = await query.GetTeamMembers(gitHubConfig["organization"], gitHubConfig["team"]);
4546
Console.WriteLine($"Org '{gitHubConfig["organization"]}' team '{gitHubConfig["team"]}' members");
46-
foreach (var member in members) {
47+
foreach (var member in members)
48+
{
4749
Console.WriteLine($" {member.Login}");
4850
}
51+
52+
var pullRequests = await query.GetOpenPullRequests(gitHubConfig["organization"], gitHubConfig["repository"]);
53+
Console.WriteLine($"Org '{gitHubConfig["organization"]}' repo '{gitHubConfig["repository"]}' open pull requests");
54+
foreach (var pullRequest in pullRequests)
55+
{
56+
Console.WriteLine($" #{pullRequest.Number} {pullRequest.Title}");
57+
Console.WriteLine($" By: {pullRequest.Author.Login}");
58+
Console.WriteLine($" Branch: {pullRequest.HeadRef.Name}");
59+
Console.WriteLine($" Labels: {String.Join(' ', pullRequest.Labels.Nodes.Select(label => label.Name))}");
60+
}
4961
}
5062
}
5163
}

0 commit comments

Comments
 (0)