Skip to content

Commit 850ea4a

Browse files
committed
(GH-3) Added FxCop and began correcting issues
- Added FxCop Nuget Package to force execution of FxCop during build - Added default xsl file for transforming XML output to be readable - Ensure that failing of build is enforced when there is a StyleCop error - Added default ruleset to be used as part of build - Began the process of correcting identified StyleCop issues
1 parent 4a8631f commit 850ea4a

15 files changed

+557
-36
lines changed

BuildScripts/CodeAnalysis.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<CodeAnalysisLogFile>..\..\BuildArtifacts\CodeAnalysis.$(AssemblyName).$(Platform).$(Configuration).xml</CodeAnalysisLogFile>
5+
</PropertyGroup>
6+
</Project>

BuildScripts/CodeAnalysisReport.xsl

Lines changed: 432 additions & 0 deletions
Large diffs are not rendered by default.

src/App/CodeAnalysisRules.ruleset

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RuleSet Name="Copy of Microsoft All Rules" Description="This rule set contains all rules. Running this rule set may result in a large number of warnings being reported. Use this rule set to get a comprehensive picture of all issues in your code. This can help you decide which of the more focused rule sets are most appropriate to run for your projects." ToolsVersion="11.0">
3+
<IncludeAll Action="Warning" />
4+
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
5+
</Rules>
6+
</RuleSet>

src/App/CommonSubOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ReleaseNotesCompiler.CLI
1212
public abstract class CommonSubOptions
1313
{
1414
[Option('u', "username", HelpText = "The username to access GitHub with.", Required = true)]
15-
public string Username { get; set; }
15+
public string UserName { get; set; }
1616
[Option('p', "password", HelpText = "The password to access GitHub with.", Required = true)]
1717
public string Password { get; set; }
1818
[Option('o', "owner", HelpText = "The owner of the repository.", Required = true)]
@@ -24,7 +24,7 @@ public abstract class CommonSubOptions
2424

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

src/App/ReleaseNotesCompiler.CLI.csproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<NuGetPackageImportStamp>eb66298a</NuGetPackageImportStamp>
1515
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1616
<RestorePackages>true</RestorePackages>
17+
<BuildToolsFxCopVersion>1.0.1</BuildToolsFxCopVersion>
1718
</PropertyGroup>
1819
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1920
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -24,15 +25,21 @@
2425
<DefineConstants>DEBUG;TRACE</DefineConstants>
2526
<ErrorReport>prompt</ErrorReport>
2627
<WarningLevel>4</WarningLevel>
28+
<RunCodeAnalysis>False</RunCodeAnalysis>
29+
<CodeAnalysisRuleSet>CodeAnalysisRules.ruleset</CodeAnalysisRuleSet>
30+
<CodeAnalysisTreatWarningsAsErrors>True</CodeAnalysisTreatWarningsAsErrors>
2731
</PropertyGroup>
2832
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2933
<PlatformTarget>AnyCPU</PlatformTarget>
3034
<DebugType>pdbonly</DebugType>
3135
<Optimize>true</Optimize>
3236
<OutputPath>bin\Release\</OutputPath>
33-
<DefineConstants>TRACE</DefineConstants>
37+
<DefineConstants>TRACE;CODE_ANALYSIS</DefineConstants>
3438
<ErrorReport>prompt</ErrorReport>
3539
<WarningLevel>4</WarningLevel>
40+
<RunCodeAnalysis>True</RunCodeAnalysis>
41+
<CodeAnalysisRuleSet>CodeAnalysisRules.ruleset</CodeAnalysisRuleSet>
42+
<CodeAnalysisTreatWarningsAsErrors>True</CodeAnalysisTreatWarningsAsErrors>
3643
</PropertyGroup>
3744
<ItemGroup>
3845
<Reference Include="CommandLine">
@@ -59,6 +66,7 @@
5966
<Compile Include="PublishSubOptions.cs" />
6067
</ItemGroup>
6168
<ItemGroup>
69+
<None Include="CodeAnalysisRules.ruleset" />
6270
<None Include="packages.config">
6371
<SubType>Designer</SubType>
6472
</None>
@@ -70,6 +78,9 @@
7078
</ProjectReference>
7179
</ItemGroup>
7280
<ItemGroup>
81+
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
82+
<Link>CustomDictionary.xml</Link>
83+
</CodeAnalysisDictionary>
7384
<Content Include="FodyWeavers.xml" />
7485
</ItemGroup>
7586
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
@@ -122,6 +133,7 @@ foreach (var item in filesToCleanup)
122133
<Import Project="..\packages\GitVersionTask.1.2.0\Build\GitVersionTask.targets" Condition="Exists('..\packages\GitVersionTask.1.2.0\Build\GitVersionTask.targets')" />
123134
<Import Project="..\packages\NuGetPackager.0.1.3\build\NuGetPackager.targets" Condition="Exists('..\packages\NuGetPackager.0.1.3\build\NuGetPackager.targets')" />
124135
<Import Project="..\packages\Fody.1.26.1\build\Fody.targets" Condition="Exists('..\packages\Fody.1.26.1\build\Fody.targets')" />
136+
<Import Project="..\..\BuildScripts\CodeAnalysis.props" Condition="Exists('..\..\BuildScripts\CodeAnalysis.props')" />
125137
<Import Project="..\..\BuildScripts\StyleCop.props" Condition="Exists('..\..\BuildScripts\StyleCop.props')" />
126138
<Import Project="..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.Targets" Condition="Exists('..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.Targets')" />
127139
<Import Project="..\packages\StyleCop.Error.MSBuild.1.0.0\build\StyleCop.Error.MSBuild.Targets" Condition="Exists('..\packages\StyleCop.Error.MSBuild.1.0.0\build\StyleCop.Error.MSBuild.Targets')" />

src/App/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="BuildTools.FxCop" version="1.0.1" targetFramework="net45" />
34
<package id="CommandLineParser" version="1.9.71" targetFramework="net45" />
45
<package id="Costura.Fody" version="1.3.2.0" targetFramework="net45" developmentDependency="true" />
56
<package id="Fody" version="1.26.1" targetFramework="net45" developmentDependency="true" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RuleSet Name="Copy of Microsoft All Rules" Description="This rule set contains all rules. Running this rule set may result in a large number of warnings being reported. Use this rule set to get a comprehensive picture of all issues in your code. This can help you decide which of the more focused rule sets are most appropriate to run for your projects." ToolsVersion="11.0">
3+
<IncludeAll Action="Warning" />
4+
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
5+
</Rules>
6+
</RuleSet>

src/Compiler/OctokitExtensions.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace ReleaseNotesCompiler
88
{
9+
using System;
910
using System.Collections.Generic;
1011
using System.Linq;
1112
using System.Threading.Tasks;
@@ -15,6 +16,11 @@ public static class OctokitExtensions
1516
{
1617
public static bool IsPullRequest(this Issue issue)
1718
{
19+
if (issue == null)
20+
{
21+
throw new ArgumentNullException("issue");
22+
}
23+
1824
return issue.PullRequest != null;
1925
}
2026

@@ -38,33 +44,18 @@ public static async Task<IEnumerable<Issue>> AllIssuesForMilestone(this GitHubCl
3844
return openIssues.Union(closedIssues);
3945
}
4046

41-
public static string HtmlUrl(this Milestone milestone)
47+
public static Uri HtmlUrl(this Milestone milestone)
4248
{
49+
if (milestone == null)
50+
{
51+
throw new ArgumentNullException("milestone");
52+
}
53+
4354
var parts = milestone.Url.AbsolutePath.Split('/');
4455
var user = parts[2];
4556
var repository = parts[3];
46-
return string.Format("https://github.com/{0}/{1}/issues?milestone={2}&state=closed", user, repository, milestone.Number);
47-
}
4857

49-
private static IEnumerable<string> FixHeaders(IEnumerable<string> lines)
50-
{
51-
var inCode = false;
52-
foreach (var line in lines)
53-
{
54-
if (line.StartsWith("```"))
55-
{
56-
inCode = !inCode;
57-
}
58-
59-
if (!inCode && line.StartsWith("#"))
60-
{
61-
yield return "###" + line;
62-
}
63-
else
64-
{
65-
yield return line;
66-
}
67-
}
58+
return new Uri(string.Format("https://github.com/{0}/{1}/issues?milestone={2}&state=closed", user, repository, milestone.Number));
6859
}
6960
}
7061
}

src/Compiler/ReleaseManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task<List<ReleaseUpdateRequired>> GetReleasesInNeedOfUpdates()
4848

4949
if (release != null)
5050
{
51-
var releaseUpdatedAt = this.GetUpdatedAt(release).ToUniversalTime();
51+
var releaseUpdatedAt = GetUpdatedAt(release).ToUniversalTime();
5252

5353
var allIssues = await this.gitHubClient.AllIssuesForMilestone(milestone);
5454

@@ -83,7 +83,7 @@ public async Task<List<ReleaseUpdateRequired>> GetReleasesInNeedOfUpdates()
8383
return releases;
8484
}
8585

86-
private DateTime GetUpdatedAt(Release release)
86+
private static DateTime GetUpdatedAt(Release release)
8787
{
8888
// we try to parse our footer
8989
var temp = release.Body.Split(new[] { " at " }, StringSplitOptions.RemoveEmptyEntries);

src/Compiler/ReleaseNotesBuilder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public async Task<string> BuildReleaseNotes()
6969
stringBuilder.AppendLine(this.targetMilestone.Description);
7070
stringBuilder.AppendLine();
7171

72-
this.AddIssues(stringBuilder, issues);
72+
AddIssues(stringBuilder, issues);
7373

7474
await this.AddFooter(stringBuilder);
7575

@@ -87,7 +87,7 @@ private static void CheckForValidLabels(Issue issue)
8787
if (count != 1)
8888
{
8989
var message = string.Format("Bad Issue {0} expected to find a single label with either 'Bug', 'Internal refactoring', 'Improvement' or 'Feature'.", issue.HtmlUrl);
90-
throw new Exception(message);
90+
throw new InvalidOperationException(message);
9191
}
9292
}
9393

@@ -111,11 +111,11 @@ private string GetCommitsLink(Milestone previousMilestone)
111111
return string.Format("https://github.com/{0}/{1}/compare/{2}...{3}", this.user, this.repository, previousMilestone.Title, this.targetMilestone.Title);
112112
}
113113

114-
private void AddIssues(StringBuilder stringBuilder, List<Issue> issues)
114+
private static void AddIssues(StringBuilder stringBuilder, List<Issue> issues)
115115
{
116-
this.Append(issues, "Feature", stringBuilder);
117-
this.Append(issues, "Improvement", stringBuilder);
118-
this.Append(issues, "Bug", stringBuilder);
116+
Append(issues, "Feature", stringBuilder);
117+
Append(issues, "Improvement", stringBuilder);
118+
Append(issues, "Bug", stringBuilder);
119119
}
120120

121121
private async Task AddFooter(StringBuilder stringBuilder)
@@ -155,7 +155,7 @@ private async Task<List<Issue>> GetIssues(Milestone milestone)
155155
return issues;
156156
}
157157

158-
private void Append(IEnumerable<Issue> issues, string label, StringBuilder stringBuilder)
158+
private static void Append(IEnumerable<Issue> issues, string label, StringBuilder stringBuilder)
159159
{
160160
var features = issues.Where(x => x.Labels.Any(l => l.Name == label)).ToList();
161161

0 commit comments

Comments
 (0)