diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/SummaryModel.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/SummaryModel.java index aefe320383..15f97f9c70 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/SummaryModel.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/SummaryModel.java @@ -10,6 +10,7 @@ import hudson.model.Run; +import io.jenkins.plugins.forensics.reference.ReferenceBuild; import io.jenkins.plugins.util.QualityGateStatus; /** @@ -155,6 +156,20 @@ public boolean isResetQualityGateVisible() { return analysisResult.getReferenceBuild(); } + /** + * Renders the reference build as an HTML link. + * + * @return the reference build + * @see #getReferenceBuild() + */ + @SuppressWarnings("unused") // Called by jelly view + public String getReferenceBuildLink() { + return facade.getReferenceLink( + analysisResult.getReferenceBuild() + .map(Run::getExternalizableId) + .orElse("-")); + } + public boolean isZeroIssuesHighscore() { return getNoIssuesSinceBuild() > 0 && analysisResult.getOwner().getNumber() > getNoIssuesSinceBuild(); } @@ -175,5 +190,9 @@ static class LabelProviderFactoryFacade { public StaticAnalysisLabelProvider get(final String id) { return new LabelProviderFactory().create(id); } + + public String getReferenceLink(final String id) { + return ReferenceBuild.getReferenceBuildLink(id); + } } } diff --git a/plugin/src/main/resources/io/jenkins/plugins/analysis/core/model/ResultAction/summary.jelly b/plugin/src/main/resources/io/jenkins/plugins/analysis/core/model/ResultAction/summary.jelly index 6ac50b9b57..12ccbeb45e 100644 --- a/plugin/src/main/resources/io/jenkins/plugins/analysis/core/model/ResultAction/summary.jelly +++ b/plugin/src/main/resources/io/jenkins/plugins/analysis/core/model/ResultAction/summary.jelly @@ -99,7 +99,7 @@
  • Reference build: - +
  • diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/SummaryModelTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/SummaryModelTest.java index c1bdbd667b..a6c4875418 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/SummaryModelTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/SummaryModelTest.java @@ -56,6 +56,7 @@ void shouldCreateTitleMessageIfThereAreNoWarnings() { .hasAnalysesCount(1) .hasQualityGateStatus(QualityGateStatus.INACTIVE) .hasReferenceBuild(Optional.empty()) + .hasReferenceBuildLink("-") .isNotZeroIssuesHighscore() .hasNoErrors() .isNotResetQualityGateVisible(); @@ -157,6 +158,7 @@ void shouldUseReferenceBuildOfResult() { Run run = mock(Run.class); when(run.getFullDisplayName()).thenReturn("Job #15"); + when(run.getExternalizableId()).thenReturn("#15"); when(run.getUrl()).thenReturn("job/my-job/15"); when(analysisResult.getReferenceBuild()).thenReturn(Optional.of(run)); @@ -164,7 +166,8 @@ void shouldUseReferenceBuildOfResult() { SummaryModel summary = createSummary(analysisResult); - assertThat(summary).hasReferenceBuild(Optional.of(run)); + assertThat(summary).hasReferenceBuild(Optional.of(run)) + .hasReferenceBuildLink("#reference-link"); } @Test @@ -209,6 +212,8 @@ private SummaryModel createSummary(final AnalysisResult analysisResult) { when(facade.get(CHECK_STYLE_ID)).thenReturn(checkStyleLabelProvider); StaticAnalysisLabelProvider pmdLabelProvider = new StaticAnalysisLabelProvider(PMD_ID, PMD_NAME); when(facade.get(PMD_ID)).thenReturn(pmdLabelProvider); + when(facade.getReferenceLink("-")).thenReturn("-"); + when(facade.getReferenceLink(startsWith("#"))).thenReturn("#reference-link"); SummaryModel summaryModel = new SummaryModel(new StaticAnalysisLabelProvider(TOOL_ID, TOOL_NAME), analysisResult, facade); summaryModel.setResetQualityGateCommand(createResetReferenceAction(false));