Skip to content

Commit

Permalink
Merge pull request #1814 from jenkinsci/JENKINS-72973-skip-delta
Browse files Browse the repository at this point in the history
[JENKINS-72973] Add an option to skip the SCM delta calculation
  • Loading branch information
uhafner authored Sep 10, 2024
2 parents 170224f + 910b358 commit 0418a85
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import io.jenkins.plugins.analysis.core.util.TrendChartType;
import io.jenkins.plugins.analysis.core.util.WarningsQualityGate;
import io.jenkins.plugins.checks.steps.ChecksInfo;
import io.jenkins.plugins.forensics.delta.DeltaCalculator.NullDeltaCalculator;
import io.jenkins.plugins.forensics.delta.DeltaCalculatorFactory;
import io.jenkins.plugins.prism.SourceCodeDirectory;
import io.jenkins.plugins.prism.SourceCodeRetention;
Expand Down Expand Up @@ -119,6 +120,7 @@ public class IssuesRecorder extends Recorder {
private transient boolean publishAllIssues; // @deprecated: use checksAnnotationScope instead

private boolean skipPostProcessing; // @since 10.6.0: by default, post-processing will be enabled
private boolean skipDeltaCalculation; // @since 11.5.0: by default, delta computation is enabled

@CheckForNull
private ChecksInfo checksInfo;
Expand Down Expand Up @@ -463,6 +465,20 @@ public void setSkipPostProcessing(final boolean skipPostProcessing) {
this.skipPostProcessing = skipPostProcessing;
}

/**
* Returns whether the SCM delta calculation for the new issue detection should be disabled.
*
* @return {@code true} if the SCM delta calculation for the new issue detection should be disabled.
*/
public boolean isSkipDeltaCalculation() {
return skipDeltaCalculation;
}

@DataBoundSetter
public void setSkipDeltaCalculation(final boolean skipDeltaCalculation) {
this.skipDeltaCalculation = skipDeltaCalculation;
}

/**
* Determines whether to fail the step on errors during the step of recording issues.
*
Expand Down Expand Up @@ -733,8 +749,9 @@ AnalysisResult publishResult(final Run<?, ?> run, final FilePath workspace, fina
logHandler.logInfoMessages(report.getInfoMessages());
logHandler.logErrorMessages(report.getErrorMessages());

var deltaCalculator = DeltaCalculatorFactory
.findDeltaCalculator(scm, run, workspace, listener, new FilteredLog());
var deltaCalculator = isSkipDeltaCalculation()
? new NullDeltaCalculator()
: DeltaCalculatorFactory.findDeltaCalculator(scm, run, workspace, listener, new FilteredLog());

IssuesPublisher publisher = new IssuesPublisher(run, annotatedReport, deltaCalculator,
new HealthDescriptor(healthy, unhealthy, minimumSeverity), qualityGates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class PublishIssuesStep extends Step implements Serializable {
private boolean ignoreQualityGate = false; // by default, a successful quality gate is mandatory
private boolean failOnError = false; // by default, it should not fail on error

private boolean skipDeltaCalculation; // @since 11.5.0: by default, delta computation is enabled
private boolean skipPublishingChecks; // by default, warnings should be published to SCM platforms
private ChecksAnnotationScope checksAnnotationScope = ChecksAnnotationScope.NEW; // @since 11.0.0

Expand Down Expand Up @@ -169,6 +170,20 @@ public boolean getFailOnError() {
return failOnError;
}

/**
* Returns whether the SCM delta calculation for the new issue detection should be disabled.
*
* @return {@code true} if the SCM delta calculation for the new issue detection should be disabled.
*/
public boolean isSkipDeltaCalculation() {
return skipDeltaCalculation;
}

@DataBoundSetter
public void setSkipDeltaCalculation(final boolean skipDeltaCalculation) {
this.skipDeltaCalculation = skipDeltaCalculation;
}

/**
* Returns whether publishing checks should be skipped.
*
Expand Down Expand Up @@ -414,8 +429,9 @@ protected ResultAction run() throws IOException, InterruptedException, IllegalSt
report.addAll(step.reports);

var workspace = getContext().get(FilePath.class);
var deltaCalculator = workspace == null ? new DeltaCalculator.NullDeltaCalculator() : DeltaCalculatorFactory
.findDeltaCalculator(step.scm, getRun(), workspace, getTaskListener(), new FilteredLog());
var deltaCalculator = workspace == null || step.isSkipDeltaCalculation()
? new DeltaCalculator.NullDeltaCalculator()
: DeltaCalculatorFactory.findDeltaCalculator(step.scm, getRun(), workspace, getTaskListener(), new FilteredLog());

IssuesPublisher publisher = new IssuesPublisher(getRun(), report,
deltaCalculator, new HealthDescriptor(step.getHealthy(), step.getUnhealthy(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class RecordIssuesStep extends Step implements Serializable {
private boolean isBlameDisabled;

private boolean skipPostProcessing; // @since 10.6.0: by default, post-processing will be enabled
private boolean skipDeltaCalculation; // @since 11.5.0: by default, delta computation is enabled
private boolean skipPublishingChecks; // by default, checks will be published
private ChecksAnnotationScope checksAnnotationScope = ChecksAnnotationScope.NEW; // @since 11.0.0

Expand Down Expand Up @@ -403,6 +404,20 @@ public void setSkipPostProcessing(final boolean skipPostProcessing) {
this.skipPostProcessing = skipPostProcessing;
}

/**
* Returns whether the SCM delta calculation for the new issue detection should be disabled.
*
* @return {@code true} if the SCM delta calculation for the new issue detection should be disabled.
*/
public boolean isSkipDeltaCalculation() {
return skipDeltaCalculation;
}

@DataBoundSetter
public void setSkipDeltaCalculation(final boolean skipDeltaCalculation) {
this.skipDeltaCalculation = skipDeltaCalculation;
}

/**
* Returns whether publishing checks should be skipped.
*
Expand Down Expand Up @@ -614,6 +629,7 @@ protected List<AnalysisResult> run() throws IOException, InterruptedException {
recorder.setAggregatingResults(step.getAggregatingResults());
recorder.setBlameDisabled(step.isSkipBlames());
recorder.setSkipPostProcessing(step.isSkipPostProcessing());
recorder.setSkipDeltaCalculation(step.isSkipDeltaCalculation());
recorder.setScm(step.getScm());
recorder.setSkipPublishingChecks(step.isSkipPublishingChecks());
recorder.setChecksAnnotationScope(step.getChecksAnnotationScope());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div>
If this option is unchecked, then the plugin analyzes the code changes between the current build and
the reference build. Currently, this feature is only available for Git and requires the
<a href="https://plugins.jenkins.io/git-forensics">git-forensics plugin</a>
to be installed. Based on this delta report, issues are then classified
as new or outstanding. Only issues that are part of the obtained diff will be marked as new.
If this operation slows down your build, you can use this option to deactivate this feature.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div>
If this option is unchecked, then the plugin analyzes the code changes between the current build and
the reference build. Currently, this feature is only available for Git and requires the
<a href="https://plugins.jenkins.io/git-forensics">git-forensics plugin</a>
to be installed. Based on this delta report, issues are then classified
as new or outstanding. Only issues that are part of the obtained diff will be marked as new.
If this operation slows down your build, you can use this option to deactivate this feature.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div>
If this option is unchecked, then the plugin analyzes the code changes between the current build and
the reference build. Currently, this feature is only available for Git and requires the
<a href="https://plugins.jenkins.io/git-forensics">git-forensics plugin</a>
to be installed. Based on this delta report, issues are then classified
as new or outstanding. Only issues that are part of the obtained diff will be marked as new.
If this operation slows down your build, you can use this option to deactivate this feature.
</div>
19 changes: 11 additions & 8 deletions plugin/src/main/resources/issues/publish-parameters.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@

<i:hr title="${%Publishing Options}"/>

<f:entry field="skipPublishingChecks">
<f:checkbox title="${%title.skipPublishingChecks}" />
<f:entry field="skipPublishingChecks" title="${%title.skipPublishingChecks}">
<f:checkbox />
</f:entry>
<f:entry title="${%title.checksAnnotationScope}" field="checksAnnotationScope">
<f:entry field="checksAnnotationScope" title="${%title.checksAnnotationScope}">
<f:select default="NEW"/>
</f:entry>
<f:entry field="failOnError">
<f:checkbox title="${%title.failOnError}"/>
</f:entry>
<f:entry field="ignoreQualityGate">
<f:checkbox title="${%title.ignoreQualityGate}"/>
<f:entry field="skipDeltaCalculation" title="${%title.skipDeltaCalculation}" >
<f:checkbox />
</f:entry>

<f:entry field="failOnError" title="${%title.failOnError}">
<f:checkbox />
</f:entry>
<f:entry field="ignoreQualityGate" title="${%title.ignoreQualityGate}">
<f:checkbox />
</f:entry>

<f:entry title="${%title.trendChartType}" field="trendChartType">
<f:select default="AGGREGATION_TOOLS"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description.reference=One important feature of the Warnings Plugin is the classification of issues as \
new, outstanding and fixed. In order to compute this classification, the plugin requires a reference build (baseline). \
new, outstanding and fixed. To compute this classification, the plugin requires a reference build (baseline). \
New, fixed, and outstanding issues are then computed by comparing the issues in the current build and in the baseline.
title.ignoreQualityGate=Ignore the results of the quality gates when determining the reference build
title.failOnError=Fail the build if errors have been reported during the execution
Expand All @@ -14,12 +14,13 @@ qualityGates.description=You can define an arbitrary number of quality gates tha
title.trendChartType=Trend Chart Type and Position

title.skipPublishingChecks=Skip publishing of checks to SCM provider platforms
title.skipDeltaCalculation=Skip SCM delta calculation to identify new issues
title.checksAnnotationScope=Select the scope of source code annotations

threshold.100.percent=100%
threshold.0.percent=0%
description.health.limit=Configure the thresholds for the build health. If left empty, then no health report is created. \
If the actual number of warnings is between the provided thresholds, then the build health is interpolated.
title.health.severities=Health Report Severities
title.health.severities=Health Report Severities
description.healthy=Report health as 100% when the number of issues is less than this value.
description.unhealthy=Report health as 0% when the number of issues is greater than this value.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@ private String createScanForIssuesStep(final String sourceDirectories) {
+ PUBLISH_ISSUES_STEP;
}

@Test
void shouldSkipDeltaCalculation() {
WorkflowJob job = createPipelineWithWorkspaceFilesWithSuffix();

createFileInWorkspace(job, "java-issues.txt",
createJavaWarning(MODIFIED_FILE, 111)
+ createJavaWarning(SCM_RESOLVER, AFFECTED_LINE));

var step = "recordIssues skipDeltaCalculation: true, "
+ "sourceDirectories: [[path: 'forensics-api']], tool: java(pattern:'**/*issues.txt', reportEncoding:'UTF-8')";
job.setDefinition(asStage(checkout(OLD_COMMIT), step));

buildSuccessfully(job); // reference build

createFileInWorkspace(job, "java-issues.txt",
createJavaWarning(MODIFIED_FILE, 111) // outstanding and modified
+ createJavaWarning(MODIFIED_FILE, 112) // new and modified
+ createJavaWarning(MODIFIED_FILE, 113) // new and modified
+ createJavaWarning(SCM_RESOLVER, AFFECTED_LINE) // outstanding (not modified)
+ createJavaWarning(MODIFIED_FILE, 2)); // new (not modified)

job.setDefinition(asStage(CHECKOUT_FORENSICS_API, "discoverReferenceBuild()", step));

AnalysisResult result = scheduleSuccessfulBuild(job);
assertThat(getConsoleLog(result)).contains(
"Detect all issues that are part of modified code",
"No relevant modified code found",
"Created analysis result for 5 issues (found 3 new issues, fixed 0 issues)");
assertThat(getConsoleLog(result)).doesNotContain(
"-> Using commit 'a6d0ef0' as latest commit for build",
"-> Using commit '3097ea1' as latest commit for build",
"-> Invoking Git delta calculator for determining the changes between commits 'a6d0ef0' and '3097ea1'",
"-> Start scanning for differences between commits...",
"Issues in modified code");
}

/**
* Checks out an existing Git repository and starts a pipeline with the record step. Verifies that the Git forensics
* plugin is correctly invoked.
Expand Down

0 comments on commit 0418a85

Please sign in to comment.