Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #22 from justaprogrammer/deserialization
Browse files Browse the repository at this point in the history
Changing how configuration is deserialized
  • Loading branch information
StanleyGoldman authored Dec 9, 2018
2 parents e59e70d + e609860 commit e006e78
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 33 deletions.
8 changes: 4 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ Here we are taking `CS0219` which is normally a warning and forcing it to be rep

#### CheckRunConfiguration <sub><sup>[src](https://github.com/justaprogrammer/BCC-MSBuildLog/blob/master/src/BCC.MSBuildLog/Model/CheckRunConfiguration.cs)</sup></sub>

+ rules (array[LogAnalyzerRule]) - Array of rules
+ name (string)
- rules (array[LogAnalyzerRule]) - Array of rules
- name (string)

#### LogAnalyzerRule <sub><sup>[src](https://github.com/justaprogrammer/BCC-MSBuildLog/blob/master/src/BCC.MSBuildLog/Model/LogAnalyzerRule.cs)</sup></sub>

+ code (string, required) - The MSBuild warning/error code to match against
+ reportAs: asIs, ignore, notice, warning, error (enum, required)
- code (string, required) - The MSBuild warning/error code to match against
- reportAs: asIs, ignore, notice, warning, error (enum, required)
22 changes: 11 additions & 11 deletions src/BCC.MSBuildLog.Tests/Services/BinaryLogProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Should_TestConsoleApp1_Warning()
"TestConsoleApp1/Program.cs",
13,
13,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"The variable 'hello' is assigned but its value is never used")
{
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
Expand Down Expand Up @@ -81,7 +81,7 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Warning_For_Other_Code()
"TestConsoleApp1/Program.cs",
13,
13,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"The variable 'hello' is assigned but its value is never used")
{
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
Expand Down Expand Up @@ -116,7 +116,7 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Warning()
"TestConsoleApp1/Program.cs",
13,
13,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"The variable 'hello' is assigned but its value is never used")
{
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
Expand Down Expand Up @@ -151,7 +151,7 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Notice()
"TestConsoleApp1/Program.cs",
13,
13,
CheckWarningLevel.Notice,
AnnotationLevel.Notice,
"The variable 'hello' is assigned but its value is never used")
{
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
Expand Down Expand Up @@ -186,7 +186,7 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Error()
"TestConsoleApp1/Program.cs",
13,
13,
CheckWarningLevel.Failure,
AnnotationLevel.Failure,
"The variable 'hello' is assigned but its value is never used")
{
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
Expand Down Expand Up @@ -232,7 +232,7 @@ public void Should_TestConsoleApp1_Error()
"TestConsoleApp1/Program.cs",
13,
13,
CheckWarningLevel.Failure,
AnnotationLevel.Failure,
"; expected")
{
Title = "CS1002: TestConsoleApp1/Program.cs(13)"
Expand All @@ -256,7 +256,7 @@ public void Should_TestConsoleApp1_CodeAnalysis()
"TestConsoleApp1/Program.cs",
20,
20,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"Microsoft.Usage : 'Program.MyClass' contains field 'Program.MyClass._inner' that is of IDisposable type: 'Program.MyOTherClass'. Change the Dispose method on 'Program.MyClass' to call Dispose or Close on this field.")
{
Title = "CA2213: TestConsoleApp1/Program.cs(20)"
Expand All @@ -282,7 +282,7 @@ public void Should_MSBLOC()
"MSBLOC.Core.Tests/Services/BinaryLogProcessorTests.cs",
56,
56,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"The variable 'filename' is assigned but its value is never used")
{
Title = "CS0219: MSBLOC.Core.Tests/Services/BinaryLogProcessorTests.cs(56)"
Expand All @@ -293,7 +293,7 @@ public void Should_MSBLOC()
"MSBLOC.Core.Tests/Services/BinaryLogProcessorTests.cs",
83,
83,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"The variable 'filename' is assigned but its value is never used")
{
Title = "CS0219: MSBLOC.Core.Tests/Services/BinaryLogProcessorTests.cs(83)"
Expand All @@ -318,7 +318,7 @@ public void Should_Parse_OctokitGraphQL()
"Octokit.GraphQL.Core/Connection.cs",
43,
43,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"Missing XML comment for publicly visible type or member 'Connection.Uri'")
{
Title = "CS1591: Octokit.GraphQL.Core/Connection.cs(43)"
Expand All @@ -329,7 +329,7 @@ public void Should_Parse_OctokitGraphQL()
"Octokit.GraphQL.Core/Connection.cs",
44,
44,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"Missing XML comment for publicly visible type or member 'Connection.CredentialStore'")
{
Title = "CS1591: Octokit.GraphQL.Core/Connection.cs(44)"
Expand Down
16 changes: 8 additions & 8 deletions src/BCC.MSBuildLog.Tests/Services/BuildLogProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void Should_Create_CheckRun_With_Warning()
Faker.System.FilePath(),
Faker.Random.Int(),
Faker.Random.Int(),
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
Faker.Lorem.Word())
};

Expand All @@ -130,7 +130,7 @@ public void Should_Create_CheckRun_With_Configuration()
Faker.System.FilePath(),
Faker.Random.Int(),
Faker.Random.Int(),
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
Faker.Lorem.Word())
};

Expand Down Expand Up @@ -174,7 +174,7 @@ public void Should_Create_CheckRun_With_Failure()
Faker.System.FilePath(),
Faker.Random.Int(),
Faker.Random.Int(),
CheckWarningLevel.Failure, Faker.Lorem.Word())
AnnotationLevel.Failure, Faker.Lorem.Word())
};

var mockBinaryLogProcessor = CreateMockBinaryLogProcessor(annotations, Faker.Lorem.Paragraph(), 0, 1);
Expand All @@ -196,13 +196,13 @@ public void Should_Create_CheckRun_With_WarningAndFailure()
Faker.System.FilePath(),
Faker.Random.Int(),
Faker.Random.Int(),
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
Faker.Lorem.Word()),
new Annotation(
Faker.System.FilePath(),
Faker.Random.Int(),
Faker.Random.Int(),
CheckWarningLevel.Failure,
AnnotationLevel.Failure,
Faker.Lorem.Word())
};

Expand All @@ -225,7 +225,7 @@ public void Should_Create_CheckRun_TestConsoleApp1_Warning()
"TestConsoleApp1/Program.cs",
13,
13,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"The variable 'hello' is assigned but its value is never used")
{
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
Expand Down Expand Up @@ -254,7 +254,7 @@ public void Should_Create_CheckRun_TestConsoleApp1_Error()
"TestConsoleApp1/Program.cs",
13,
13,
CheckWarningLevel.Failure,
AnnotationLevel.Failure,
"; expected")
{
Title = "CS1002: TestConsoleApp1/Program.cs(13)"
Expand Down Expand Up @@ -283,7 +283,7 @@ public void Should_Create_CheckRun_TestConsoleApp1_CodeAnalysis()
"TestConsoleApp1/Program.cs",
20,
20,
CheckWarningLevel.Warning,
AnnotationLevel.Warning,
"Microsoft.Usage : 'Program.MyClass' contains field 'Program.MyClass._inner' that is of IDisposable type: 'Program.MyOTherClass'. Change the Dispose method on 'Program.MyClass' to call Dispose or Close on this field.")
{
Title = "CA2213: TestConsoleApp1/Program.cs(20)"
Expand Down
2 changes: 1 addition & 1 deletion src/BCC.MSBuildLog/BCC.MSBuildLog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BCC-Core" Version="0.1.6" />
<PackageReference Include="BCC-Core" Version="0.1.7" />
<PackageReference Include="FluentCommandLineParser" Version="1.4.3" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="FluentCommandLineParser-netstandard" Version="1.4.3.13" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
<PackageReference Include="JetBrains.Annotations" Version="2018.2.1" />
Expand Down
14 changes: 7 additions & 7 deletions src/BCC.MSBuildLog/Services/BinaryLogProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public LogData ProcessLog(string binLogPath, string cloneRoot, string owner, str
if (buildWarning == null && buildError == null)
continue;

CheckWarningLevel checkWarningLevel;
AnnotationLevel checkWarningLevel;
string buildCode;
string projectFile;
string file;
Expand All @@ -66,7 +66,7 @@ public LogData ProcessLog(string binLogPath, string cloneRoot, string owner, str
warningCount++;
recordTypeString = "Warning";

checkWarningLevel = CheckWarningLevel.Warning;
checkWarningLevel = AnnotationLevel.Warning;
buildCode = buildWarning.Code;
projectFile = buildWarning.ProjectFile;
file = buildWarning.File;
Expand All @@ -80,7 +80,7 @@ public LogData ProcessLog(string binLogPath, string cloneRoot, string owner, str
errorCount++;
recordTypeString = "Error";

checkWarningLevel = CheckWarningLevel.Failure;
checkWarningLevel = AnnotationLevel.Failure;
buildCode = buildError.Code;
projectFile = buildError.ProjectFile;
file = buildError.File;
Expand Down Expand Up @@ -118,13 +118,13 @@ public LogData ProcessLog(string binLogPath, string cloneRoot, string owner, str
case ReportAs.AsIs:
break;
case ReportAs.Notice:
checkWarningLevel = CheckWarningLevel.Notice;
checkWarningLevel = AnnotationLevel.Notice;
break;
case ReportAs.Warning:
checkWarningLevel = CheckWarningLevel.Warning;
checkWarningLevel = AnnotationLevel.Warning;
break;
case ReportAs.Error:
checkWarningLevel = CheckWarningLevel.Failure;
checkWarningLevel = AnnotationLevel.Failure;
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down Expand Up @@ -167,7 +167,7 @@ public LogData ProcessLog(string binLogPath, string cloneRoot, string owner, str
};
}

private Annotation CreateAnnotation(CheckWarningLevel checkWarningLevel, [NotNull] string cloneRoot, [NotNull] string title, [NotNull] string message, int lineNumber, int endLineNumber, string getFilePath)
private Annotation CreateAnnotation(AnnotationLevel checkWarningLevel, [NotNull] string cloneRoot, [NotNull] string title, [NotNull] string message, int lineNumber, int endLineNumber, string getFilePath)
{
if (cloneRoot == null)
{
Expand Down
15 changes: 13 additions & 2 deletions src/BCC.MSBuildLog/Services/BuildLogProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;

namespace BCC.MSBuildLog.Services
{
Expand Down Expand Up @@ -57,14 +59,23 @@ public void Proces(string inputFile, string outputFile, string cloneRoot, string
throw new InvalidOperationException($"Content of configuration file `{configurationFile}` is null or empty.");
}

configuration = JsonConvert.DeserializeObject<CheckRunConfiguration>(configurationString);
configuration = JsonConvert.DeserializeObject<CheckRunConfiguration>(configurationString, new JsonSerializerSettings
{
Formatting = Formatting.None,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new List<JsonConverter>
{
new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy() }
},
MissingMemberHandling = MissingMemberHandling.Error
});
}

var dateTimeOffset = DateTimeOffset.Now;
var logData = _binaryLogProcessor.ProcessLog(inputFile, cloneRoot, owner, repo, hash, configuration);

var hasAnyFailure = logData.Annotations.Any() &&
logData.Annotations.Any(annotation => annotation.CheckWarningLevel == CheckWarningLevel.Failure);
logData.Annotations.Any(annotation => annotation.AnnotationLevel == AnnotationLevel.Failure);

var stringBuilder = new StringBuilder();
stringBuilder.Append(logData.ErrorCount.ToString());
Expand Down

0 comments on commit e006e78

Please sign in to comment.