Skip to content

Commit f384435

Browse files
committed
(maint) Code Refactoring
- Based on issues from StyleCop, and ReSharper
1 parent 95255c1 commit f384435

File tree

11 files changed

+66
-33
lines changed

11 files changed

+66
-33
lines changed

Source/GitHubReleaseManager.Cli/BaseGitHubSubConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public abstract class BaseGitHubSubConfig : BaseSubOptions
2424

2525
public GitHubClient CreateGitHubClient()
2626
{
27-
var creds = new Credentials(this.UserName, this.Password);
28-
var github = new GitHubClient(new ProductHeaderValue("GitHubReleaseManager")) { Credentials = creds };
27+
var credentials = new Credentials(this.UserName, this.Password);
28+
var github = new GitHubClient(new ProductHeaderValue("GitHubReleaseManager")) { Credentials = credentials };
2929
return github;
3030
}
3131
}

Source/GitHubReleaseManager.Cli/CreateSubOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CreateSubOptions : CommonSubOptions
1313
[Option('a', "asset", HelpText = "Path to the file to include in the release.", Required = false)]
1414
public string AssetPath { get; set; }
1515

16-
[Option('t', "targetcommitish", HelpText = "The commit to tag. Can be a branch or SHA. Defaults to repo's default branch.", Required = false)]
16+
[Option('t', "targetcommitish", HelpText = "The commit to tag. Can be a branch or SHA. Defaults to repository's default branch.", Required = false)]
1717
public string TargetCommitish { get; set; }
1818
}
1919
}

Source/GitHubReleaseManager.Cli/Program.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,48 +35,75 @@ private static int Main(string[] args)
3535
options,
3636
(verb, subOptions) =>
3737
{
38-
if (subOptions != null)
38+
result = 1;
39+
40+
var baseSubOptions = subOptions as BaseSubOptions;
41+
if (baseSubOptions != null)
3942
{
40-
if (string.IsNullOrEmpty(((BaseSubOptions)subOptions).TargetPath))
43+
if (string.IsNullOrEmpty(baseSubOptions.TargetPath))
4144
{
42-
((BaseSubOptions)subOptions).TargetPath = Environment.CurrentDirectory;
45+
baseSubOptions.TargetPath = Environment.CurrentDirectory;
4346
}
4447

45-
ConfigureLogging(((BaseSubOptions)subOptions).LogFilePath);
48+
ConfigureLogging(baseSubOptions.LogFilePath);
4649
}
4750

4851
var fileSystem = new FileSystem();
4952

5053
if (verb == "create")
5154
{
52-
result = CreateReleaseAsync((CreateSubOptions)subOptions, fileSystem).Result;
55+
var createSubOptions = baseSubOptions as CreateSubOptions;
56+
if (createSubOptions != null)
57+
{
58+
result = CreateReleaseAsync(createSubOptions, fileSystem).Result;
59+
}
5360
}
5461

5562
if (verb == "close")
5663
{
57-
result = CloseMilestoneAsync((CloseSubOptions)subOptions).Result;
64+
var closeSubOptions = baseSubOptions as CloseSubOptions;
65+
if (closeSubOptions != null)
66+
{
67+
result = CloseMilestoneAsync(closeSubOptions).Result;
68+
}
5869
}
5970

6071
if (verb == "publish")
6172
{
62-
result = CloseAndPublishReleaseAsync((PublishSubOptions)subOptions).Result;
73+
var publishSubOptions = baseSubOptions as PublishSubOptions;
74+
if (publishSubOptions != null)
75+
{
76+
result = CloseAndPublishReleaseAsync(publishSubOptions).Result;
77+
}
6378
}
6479

6580
if (verb == "export")
6681
{
67-
result = ExportReleasesAsync((ExportSubOptions)subOptions).Result;
82+
var exportSubOptions = baseSubOptions as ExportSubOptions;
83+
if (exportSubOptions != null)
84+
{
85+
result = ExportReleasesAsync(exportSubOptions).Result;
86+
}
6887
}
6988

7089
if (verb == "init")
7190
{
72-
ConfigurationProvider.WriteSample(((InitSubOptions)subOptions).TargetPath, fileSystem);
73-
result = 0;
91+
var initSubOptions = baseSubOptions as InitSubOptions;
92+
if (initSubOptions != null)
93+
{
94+
ConfigurationProvider.WriteSample(initSubOptions.TargetPath, fileSystem);
95+
result = 0;
96+
}
7497
}
7598

7699
if (verb == "showconfig")
77100
{
78-
Console.WriteLine(ConfigurationProvider.GetEffectiveConfigAsString(((ShowConfigSubOptions)subOptions).TargetPath, fileSystem));
79-
result = 0;
101+
var showConfigSubOptions = baseSubOptions as ShowConfigSubOptions;
102+
if (showConfigSubOptions != null)
103+
{
104+
Console.WriteLine(ConfigurationProvider.GetEffectiveConfigAsString(showConfigSubOptions.TargetPath, fileSystem));
105+
result = 0;
106+
}
80107
}
81108
}))
82109
{

Source/GitHubReleaseManager.Tests/FakeGitHubClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public FakeGitHubClient()
2020
this.Issues = new List<Issue>();
2121
}
2222

23-
public List<Milestone> Milestones { get; set; }
23+
public List<Milestone> Milestones { get; private set; }
2424

25-
public List<Issue> Issues { get; set; }
25+
public List<Issue> Issues { get; private set; }
2626

27-
public int NumberOfCommits { get; set; }
27+
public int NumberOfCommits { private get; set; }
2828

2929
public Task<int> GetNumberOfCommitsBetween(Milestone previousMilestone, Milestone currentMilestone)
3030
{

Source/GitHubReleaseManager.Tests/Helper.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
namespace GitHubReleaseManager.Tests
1+
//-----------------------------------------------------------------------
2+
// <copyright file="Helper.cs" company="gep13">
3+
// Copyright (c) gep13. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------
6+
7+
namespace GitHubReleaseManager.Tests
28
{
39
using System;
410
using System.Net;
@@ -7,27 +13,30 @@
713
public static class Helper
814
{
915
// From https://github.com/octokit/octokit.net/blob/master/Octokit.Tests.Integration/Helper.cs
10-
11-
static readonly Lazy<Credentials> _credentialsThunk = new Lazy<Credentials>(() =>
16+
private static readonly Lazy<Credentials> CredentialsThunk = new Lazy<Credentials>(() =>
1217
{
1318
var githubUsername = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBUSERNAME");
1419

1520
var githubToken = Environment.GetEnvironmentVariable("OCTOKIT_OAUTHTOKEN");
1621

1722
if (githubToken != null)
23+
{
1824
return new Credentials(githubToken);
25+
}
1926

2027
var githubPassword = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBPASSWORD");
2128

2229
if (githubUsername == null || githubPassword == null)
30+
{
2331
return Credentials.Anonymous;
32+
}
2433

2534
return new Credentials(githubUsername, githubPassword);
2635
});
2736

2837
public static Credentials Credentials
2938
{
30-
get { return _credentialsThunk.Value; }
39+
get { return CredentialsThunk.Value; }
3140
}
3241

3342
public static IWebProxy Proxy
@@ -45,4 +54,4 @@ public static IWebProxy Proxy
4554
}
4655
}
4756
}
48-
}
57+
}

Source/GitHubReleaseManager.Tests/ReleaseNotesBuilderIntegrationTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace GitHubReleaseManager.Tests
1111
using GitHubReleaseManager;
1212
using GitHubReleaseManager.Configuration;
1313
using GitHubReleaseManager.Helpers;
14-
1514
using NUnit.Framework;
1615

1716
[TestFixture]

Source/GitHubReleaseManager.Tests/ReleaseNotesBuilderTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ namespace GitHubReleaseManager.Tests
99
using System;
1010
using System.Linq;
1111
using ApprovalTests;
12-
1312
using GitHubReleaseManager.Configuration;
1413
using GitHubReleaseManager.Helpers;
15-
1614
using NUnit.Framework;
1715
using Octokit;
1816

@@ -103,7 +101,7 @@ private static void AcceptTest(int commits, params Issue[] issues)
103101
fakeClient.Issues.Add(issue);
104102
}
105103

106-
var builder = new ReleaseNotesBuilder(fakeClient, "TestUser", "FakeRepo", "1.2.3", configuration);
104+
var builder = new ReleaseNotesBuilder(fakeClient, "TestUser", "FakeRepository", "1.2.3", configuration);
107105
var notes = builder.BuildReleaseNotes().Result;
108106

109107
Approvals.Verify(notes);

Source/GitHubReleaseManager/Configuration/Config.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public Config()
3232
public string ExportRegex { get; set; }
3333

3434
[YamlMember(Alias = "issue-labels-include")]
35-
public IList<string> IssueLabelsInclude { get; set; }
35+
public IList<string> IssueLabelsInclude { get; private set; }
3636

3737
[YamlMember(Alias = "issue-labels-exclude")]
38-
public IList<string> IssueLabelsExclude { get; set; }
38+
public IList<string> IssueLabelsExclude { get; private set; }
3939
}
4040
}

Source/GitHubReleaseManager/Logger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static Logger()
2121

2222
public static Action<string> WriteError { get; set; }
2323

24-
public static void Reset()
24+
private static void Reset()
2525
{
2626
WriteInfo = s => { throw new Exception("Logger not defined."); };
2727
WriteWarning = s => { throw new Exception("Logger not defined."); };

Source/GitHubReleaseManager/OctokitExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public static async Task<IEnumerable<Issue>> AllIssuesForMilestone(this GitHubCl
2929
{
3030
var closedIssueRequest = new RepositoryIssueRequest
3131
{
32-
Milestone = milestone.Number.ToString(),
32+
Milestone = milestone.Number.ToString(CultureInfo.InvariantCulture),
3333
State = ItemState.Closed
3434
};
3535
var openIssueRequest = new RepositoryIssueRequest
3636
{
37-
Milestone = milestone.Number.ToString(),
37+
Milestone = milestone.Number.ToString(CultureInfo.InvariantCulture),
3838
State = ItemState.Open
3939
};
4040
var parts = milestone.Url.AbsolutePath.Split('/');

0 commit comments

Comments
 (0)