Skip to content

Commit 827dc4b

Browse files
authored
Merge pull request #3 from openrails/feature/reformat-code
refactor: Change code formatting to match editor default
2 parents 97a8364 + 482ed3e commit 827dc4b

File tree

6 files changed

+174
-175
lines changed

6 files changed

+174
-175
lines changed

.editorconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
root = true
33
charset = utf-8
44
indent_size = 4
5-
indent_style = tab
5+
indent_style = space
66
insert_final_newline = true
77
trim_trailing_whitespace = true
88

99
[*.md]
1010
indent_size = 2
11-
indent_style = space

GitHub/GraphPullRequest.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@
22

33
namespace Open_Rails_Code_Bot.GitHub
44
{
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-
}
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+
}
1515

16-
class GraphPullRequestAuthor
17-
{
18-
public Uri Url;
19-
public string Login;
20-
}
16+
class GraphPullRequestAuthor
17+
{
18+
public Uri Url;
19+
public string Login;
20+
}
2121

22-
class GraphPullRequestRef
23-
{
24-
public string Prefix;
25-
public string Name;
26-
}
22+
class GraphPullRequestRef
23+
{
24+
public string Prefix;
25+
public string Name;
26+
}
2727

28-
class GraphPullRequestLabels
29-
{
30-
public GraphPullRequestLabelNode[] Nodes;
31-
}
28+
class GraphPullRequestLabels
29+
{
30+
public GraphPullRequestLabelNode[] Nodes;
31+
}
3232

33-
class GraphPullRequestLabelNode
34-
{
35-
public string Name;
36-
}
33+
class GraphPullRequestLabelNode
34+
{
35+
public string Name;
36+
}
3737
}

GitHub/GraphQuery.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Open_Rails_Code_Bot.GitHub
44
{
5-
class GraphQuery
6-
{
7-
[JsonProperty("query")]
8-
public string Query;
9-
}
5+
class GraphQuery
6+
{
7+
[JsonProperty("query")]
8+
public string Query;
9+
}
1010
}

GitHub/GraphTeamMember.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Open_Rails_Code_Bot.GitHub
44
{
5-
class GraphTeamMember
6-
{
7-
public Uri Url;
8-
public string Login;
9-
public string Name;
10-
}
5+
class GraphTeamMember
6+
{
7+
public Uri Url;
8+
public string Login;
9+
public string Name;
10+
}
1111
}

GitHub/Query.cs

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,83 +8,83 @@
88

99
namespace Open_Rails_Code_Bot.GitHub
1010
{
11-
class Query
12-
{
13-
const string Endpoint = "https://api.github.com/graphql";
11+
class Query
12+
{
13+
const string Endpoint = "https://api.github.com/graphql";
1414

15-
readonly string Token;
15+
readonly string Token;
1616

17-
HttpClient Client = new HttpClient();
17+
HttpClient Client = new HttpClient();
1818

19-
public Query(string token)
20-
{
21-
Token = token;
22-
}
19+
public Query(string token)
20+
{
21+
Token = token;
22+
}
2323

24-
internal async Task<JObject> Get(string query)
25-
{
26-
var request = new HttpRequestMessage(HttpMethod.Post, Endpoint);
27-
request.Headers.UserAgent.Clear();
28-
request.Headers.UserAgent.Add(new ProductInfoHeaderValue("Open-Rails-Code-Bot", "1.0"));
29-
request.Headers.Authorization = new AuthenticationHeaderValue("bearer", Token);
30-
var graphQuery = new GraphQuery { Query = $"query {{ {query} }}" };
31-
var graphQueryJson = JsonConvert.SerializeObject(graphQuery);
32-
request.Content = new StringContent(graphQueryJson, Encoding.UTF8, "application/json");
33-
var response = await Client.SendAsync(request);
34-
var text = await response.Content.ReadAsStringAsync();
35-
return JObject.Parse(text);
36-
}
24+
internal async Task<JObject> Get(string query)
25+
{
26+
var request = new HttpRequestMessage(HttpMethod.Post, Endpoint);
27+
request.Headers.UserAgent.Clear();
28+
request.Headers.UserAgent.Add(new ProductInfoHeaderValue("Open-Rails-Code-Bot", "1.0"));
29+
request.Headers.Authorization = new AuthenticationHeaderValue("bearer", Token);
30+
var graphQuery = new GraphQuery { Query = $"query {{ {query} }}" };
31+
var graphQueryJson = JsonConvert.SerializeObject(graphQuery);
32+
request.Content = new StringContent(graphQueryJson, Encoding.UTF8, "application/json");
33+
var response = await Client.SendAsync(request);
34+
var text = await response.Content.ReadAsStringAsync();
35+
return JObject.Parse(text);
36+
}
3737

38-
public async Task<IReadOnlyList<GraphTeamMember>> GetTeamMembers(string organization, string team)
39-
{
40-
var query = @"
41-
organization(login: """ + organization + @""") {
42-
team(slug: """ + team + @""") {
43-
members {
44-
nodes {
45-
url
46-
login
47-
name
48-
}
49-
}
50-
}
51-
}
52-
";
53-
var response = await Get(query);
54-
return response["data"]["organization"]["team"]["members"]["nodes"].ToObject<GraphTeamMember[]>();
55-
}
38+
public async Task<IReadOnlyList<GraphTeamMember>> GetTeamMembers(string organization, string team)
39+
{
40+
var query = @"
41+
organization(login: """ + organization + @""") {
42+
team(slug: """ + team + @""") {
43+
members {
44+
nodes {
45+
url
46+
login
47+
name
48+
}
49+
}
50+
}
51+
}
52+
";
53+
var response = await Get(query);
54+
return response["data"]["organization"]["team"]["members"]["nodes"].ToObject<GraphTeamMember[]>();
55+
}
5656

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[]>();
88-
}
89-
}
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[]>();
88+
}
89+
}
9090
}

Program.cs

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,72 @@
88

99
namespace Open_Rails_Code_Bot
1010
{
11-
class Program
12-
{
13-
static void Main(string[] args)
14-
{
15-
var config = new CommandLineParser.Arguments.FileArgument('c', "config")
16-
{
17-
ForcedDefaultValue = new FileInfo("config.json")
18-
};
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
var config = new CommandLineParser.Arguments.FileArgument('c', "config")
16+
{
17+
ForcedDefaultValue = new FileInfo("config.json")
18+
};
1919

20-
var commandLineParser = new CommandLineParser.CommandLineParser()
21-
{
22-
Arguments = {
23-
config,
24-
}
25-
};
20+
var commandLineParser = new CommandLineParser.CommandLineParser()
21+
{
22+
Arguments = {
23+
config,
24+
}
25+
};
2626

27-
try
28-
{
29-
commandLineParser.ParseCommandLine(args);
27+
try
28+
{
29+
commandLineParser.ParseCommandLine(args);
3030

31-
AsyncMain(new ConfigurationBuilder()
32-
.AddJsonFile(config.Value.FullName, true)
33-
.Build()).Wait();
34-
}
35-
catch (CommandLineParser.Exceptions.CommandLineException e)
36-
{
37-
Console.WriteLine(e.Message);
38-
}
39-
}
31+
AsyncMain(new ConfigurationBuilder()
32+
.AddJsonFile(config.Value.FullName, true)
33+
.Build()).Wait();
34+
}
35+
catch (CommandLineParser.Exceptions.CommandLineException e)
36+
{
37+
Console.WriteLine(e.Message);
38+
}
39+
}
4040

41-
static async Task AsyncMain(IConfigurationRoot config)
42-
{
43-
var gitHubConfig = config.GetSection("github");
44-
var query = new Query(gitHubConfig["token"]);
41+
static async Task AsyncMain(IConfigurationRoot config)
42+
{
43+
var gitHubConfig = config.GetSection("github");
44+
var query = new Query(gitHubConfig["token"]);
4545

46-
var members = await query.GetTeamMembers(gitHubConfig["organization"], gitHubConfig["team"]);
47-
Console.WriteLine($"Org '{gitHubConfig["organization"]}' team '{gitHubConfig["team"]}' members ({members.Count})");
48-
foreach (var member in members)
49-
{
50-
Console.WriteLine($" {member.Login}");
51-
}
52-
var memberLogins = members.Select(member => member.Login).ToHashSet();
46+
var members = await query.GetTeamMembers(gitHubConfig["organization"], gitHubConfig["team"]);
47+
Console.WriteLine($"Org '{gitHubConfig["organization"]}' team '{gitHubConfig["team"]}' members ({members.Count})");
48+
foreach (var member in members)
49+
{
50+
Console.WriteLine($" {member.Login}");
51+
}
52+
var memberLogins = members.Select(member => member.Login).ToHashSet();
5353

54-
var pullRequests = await query.GetOpenPullRequests(gitHubConfig["organization"], gitHubConfig["repository"]);
55-
var autoMergePullRequests = new List<GraphPullRequest>();
56-
Console.WriteLine($"Org '{gitHubConfig["organization"]}' repo '{gitHubConfig["repository"]}' open pull requests ({pullRequests.Count})");
57-
foreach (var pullRequest in pullRequests)
58-
{
59-
var autoMerge = memberLogins.Contains(pullRequest.Author.Login)
60-
&& !pullRequest.Labels.Nodes.Any(label => label.Name == gitHubConfig["excludeLabel"]);
61-
Console.WriteLine($" #{pullRequest.Number} {pullRequest.Title}");
62-
Console.WriteLine($" By: {pullRequest.Author.Login}");
63-
Console.WriteLine($" Branch: {pullRequest.HeadRef.Name}");
64-
Console.WriteLine($" Labels: {String.Join(' ', pullRequest.Labels.Nodes.Select(label => label.Name))}");
65-
Console.WriteLine($" Allowed to auto-merge? {autoMerge}");
66-
if (autoMerge)
67-
{
68-
autoMergePullRequests.Add(pullRequest);
69-
}
70-
}
54+
var pullRequests = await query.GetOpenPullRequests(gitHubConfig["organization"], gitHubConfig["repository"]);
55+
var autoMergePullRequests = new List<GraphPullRequest>();
56+
Console.WriteLine($"Org '{gitHubConfig["organization"]}' repo '{gitHubConfig["repository"]}' open pull requests ({pullRequests.Count})");
57+
foreach (var pullRequest in pullRequests)
58+
{
59+
var autoMerge = memberLogins.Contains(pullRequest.Author.Login)
60+
&& !pullRequest.Labels.Nodes.Any(label => label.Name == gitHubConfig["excludeLabel"]);
61+
Console.WriteLine($" #{pullRequest.Number} {pullRequest.Title}");
62+
Console.WriteLine($" By: {pullRequest.Author.Login}");
63+
Console.WriteLine($" Branch: {pullRequest.HeadRef.Name}");
64+
Console.WriteLine($" Labels: {String.Join(' ', pullRequest.Labels.Nodes.Select(label => label.Name))}");
65+
Console.WriteLine($" Allowed to auto-merge? {autoMerge}");
66+
if (autoMerge)
67+
{
68+
autoMergePullRequests.Add(pullRequest);
69+
}
70+
}
7171

72-
Console.WriteLine($"Org '{gitHubConfig["organization"]}' repo '{gitHubConfig["repository"]}' auto-merge pull requests ({autoMergePullRequests.Count})");
73-
foreach (var pullRequest in autoMergePullRequests)
74-
{
75-
Console.WriteLine($" #{pullRequest.Number} {pullRequest.Title}");
76-
}
77-
}
78-
}
72+
Console.WriteLine($"Org '{gitHubConfig["organization"]}' repo '{gitHubConfig["repository"]}' auto-merge pull requests ({autoMergePullRequests.Count})");
73+
foreach (var pullRequest in autoMergePullRequests)
74+
{
75+
Console.WriteLine($" #{pullRequest.Number} {pullRequest.Title}");
76+
}
77+
}
78+
}
7979
}

0 commit comments

Comments
 (0)