Skip to content

Commit

Permalink
Merge pull request #1697 from jenkinsci/reference-build-link
Browse files Browse the repository at this point in the history
Remove icon from reference link as it is broken in core again
  • Loading branch information
uhafner authored Mar 6, 2024
2 parents c98f3c8 + 1591ab4 commit a476957
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import hudson.model.Run;

import io.jenkins.plugins.forensics.reference.ReferenceBuild;
import io.jenkins.plugins.util.QualityGateStatus;

/**
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<j:set var="r" value="${s.referenceBuild.get()}"/>
<li>
Reference build:
<t:buildLink jobName="${r.parent.displayName}" job="${r.parent}" number="${r.number}"/>
<j:out value="${s.referenceBuildLink}"/>
</li>
</j:if>
<j:if test="${s.qualityGateStatus.name() != 'INACTIVE'}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void shouldCreateTitleMessageIfThereAreNoWarnings() {
.hasAnalysesCount(1)
.hasQualityGateStatus(QualityGateStatus.INACTIVE)
.hasReferenceBuild(Optional.empty())
.hasReferenceBuildLink("-")
.isNotZeroIssuesHighscore()
.hasNoErrors()
.isNotResetQualityGateVisible();
Expand Down Expand Up @@ -157,14 +158,16 @@ 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));

when(analysisResult.getBuild()).thenReturn(new Build(2));

SummaryModel summary = createSummary(analysisResult);

assertThat(summary).hasReferenceBuild(Optional.of(run));
assertThat(summary).hasReferenceBuild(Optional.of(run))
.hasReferenceBuildLink("#reference-link");
}

@Test
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit a476957

Please sign in to comment.