From 80bda6fd7cc586c3aff1264d6fcc2d62276d1cfd Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 24 Jun 2024 21:53:12 +0200 Subject: [PATCH] Set BaselineState when no existing issues are passed but BaselineGuid is set --- .../SarifIssueReportGeneratorTests.cs | 27 +++++++++++++++++++ .../SarifIssueReportGenerator.cs | 3 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Cake.Issues.Reporting.Sarif.Tests/SarifIssueReportGeneratorTests.cs b/src/Cake.Issues.Reporting.Sarif.Tests/SarifIssueReportGeneratorTests.cs index 150d51b4c..90b2e438e 100644 --- a/src/Cake.Issues.Reporting.Sarif.Tests/SarifIssueReportGeneratorTests.cs +++ b/src/Cake.Issues.Reporting.Sarif.Tests/SarifIssueReportGeneratorTests.cs @@ -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 + { + IssueBuilder + .NewIssue("Message Foo 1.", "ProviderType Foo", "ProviderName Foo") + .Create(), + + }; + + // When + var logContents = fixture.CreateReport(issues); + + // Then + var sarifLog = JsonConvert.DeserializeObject(logContents); + + var run = sarifLog.Runs.ShouldHaveSingleItem(); + var result = run.Results.ShouldHaveSingleItem(); + result.BaselineState.ShouldBe(BaselineState.New); + } } diff --git a/src/Cake.Issues.Reporting.Sarif/SarifIssueReportGenerator.cs b/src/Cake.Issues.Reporting.Sarif/SarifIssueReportGenerator.cs index 98cc0b5aa..ebc9ea11a 100644 --- a/src/Cake.Issues.Reporting.Sarif/SarifIssueReportGenerator.cs +++ b/src/Cake.Issues.Reporting.Sarif/SarifIssueReportGenerator.cs @@ -49,8 +49,7 @@ protected override FilePath InternalCreateReport(IEnumerable issues) List 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);