Skip to content

Commit

Permalink
Set BaselineState when no existing issues are passed but BaselineGuid…
Browse files Browse the repository at this point in the history
… is set
  • Loading branch information
pascalberger committed Jun 24, 2024
1 parent 6476749 commit 80bda6f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1078,4 +1078,31 @@ public void Should_Generate_Report_With_BaseLineState_None_If_BaselineGuid_Is_No
result.BaselineState.ShouldBe(BaselineState.None);
}
}

[Fact]
public void Should_Generate_Report_With_BaseLineState_New_If_No_Existing_Issues()
{
// Given
var fixture = new SarifIssueReportFixture();
fixture.SarifIssueReportFormatSettings.BaselineGuid = Guid.NewGuid();

var issues =
new List<IIssue>
{
IssueBuilder
.NewIssue("Message Foo 1.", "ProviderType Foo", "ProviderName Foo")
.Create(),

};

// When
var logContents = fixture.CreateReport(issues);

// Then
var sarifLog = JsonConvert.DeserializeObject<SarifLog>(logContents);

var run = sarifLog.Runs.ShouldHaveSingleItem();
var result = run.Results.ShouldHaveSingleItem();
result.BaselineState.ShouldBe(BaselineState.New);
}
}
3 changes: 1 addition & 2 deletions src/Cake.Issues.Reporting.Sarif/SarifIssueReportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ protected override FilePath InternalCreateReport(IEnumerable<IIssue> issues)

List<SarifIssue> sarifIssues = [];

if (this.sarifIssueReportFormatSettings.BaselineGuid != Guid.Empty &&
this.sarifIssueReportFormatSettings.ExistingIssues.Count > 0)
if (this.sarifIssueReportFormatSettings.BaselineGuid != Guid.Empty)
{
var issueComparerOnlyPersistentProperties = new IIssueComparer(true);
var issueComparerAllProperties = new IIssueComparer(false);
Expand Down

0 comments on commit 80bda6f

Please # to comment.