Skip to content

Commit 49bb74e

Browse files
authored
Add tests results to info bar in console (#725)
1 parent 8bb7bb7 commit 49bb74e

File tree

6 files changed

+74
-37
lines changed

6 files changed

+74
-37
lines changed

pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
<artifactId>github-branch-source</artifactId>
7373
<optional>true</optional>
7474
</dependency>
75+
<dependency>
76+
<groupId>org.jenkins-ci.plugins</groupId>
77+
<artifactId>junit</artifactId>
78+
<optional>true</optional>
79+
</dependency>
7580
<dependency>
7681
<groupId>org.jenkins-ci.plugins</groupId>
7782
<artifactId>metrics</artifactId>

src/main/java/io/jenkins/plugins/pipelinegraphview/cards/RunDetailsItem.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ public class RunDetailsItem {
88
private final String text;
99
private final String href;
1010
private final boolean separator;
11+
private final String tooltip;
1112

12-
RunDetailsItem(String icon, String text, String href, boolean separator) {
13+
RunDetailsItem(String icon, String text, String href, boolean separator, String tooltip) {
1314
this.icon = icon;
1415
this.text = text;
1516
this.href = href;
1617
this.separator = separator;
18+
this.tooltip = tooltip;
1719
}
1820

1921
public String getIcon() {
@@ -28,6 +30,10 @@ public String getHref() {
2830
return href;
2931
}
3032

33+
public String getTooltip() {
34+
return tooltip;
35+
}
36+
3137
public boolean isSeparator() {
3238
return separator;
3339
}
@@ -37,6 +43,7 @@ public static class Builder {
3743
private String icon;
3844
private String text;
3945
private String href;
46+
private String tooltip;
4047
private boolean separator;
4148

4249
public Builder text(String text) {
@@ -49,6 +56,11 @@ public Builder icon(String icon) {
4956
return this;
5057
}
5158

59+
public Builder tooltip(String tooltip) {
60+
this.tooltip = tooltip;
61+
return this;
62+
}
63+
5264
public Builder ionicon(String ionicon) {
5365
this.icon = String.format("symbol-%s plugin-ionicons-api", ionicon);
5466
return this;
@@ -68,7 +80,7 @@ public RunDetailsItem build() {
6880
if (!separator) {
6981
requireNonNull(icon);
7082
}
71-
return new RunDetailsItem(icon, text, href, separator);
83+
return new RunDetailsItem(icon, text, href, separator, tooltip);
7284
}
7385
}
7486
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.jenkins.plugins.pipelinegraphview.cards.items;
2+
3+
import hudson.tasks.test.AbstractTestResultAction;
4+
import io.jenkins.plugins.pipelinegraphview.Messages;
5+
import io.jenkins.plugins.pipelinegraphview.cards.RunDetailsItem;
6+
import java.util.Optional;
7+
import jenkins.model.Jenkins;
8+
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
9+
10+
public class TestResultRunDetailsItems {
11+
12+
public static Optional<RunDetailsItem> get(WorkflowRun run) {
13+
boolean junitInstalled = Jenkins.get().getPlugin("junit") != null;
14+
if (!junitInstalled) {
15+
return Optional.empty();
16+
}
17+
18+
AbstractTestResultAction<?> action = run.getAction(AbstractTestResultAction.class);
19+
20+
if (action != null) {
21+
RunDetailsItem testResult = new RunDetailsItem.Builder()
22+
.ionicon("clipboard-outline")
23+
.text(Messages.testResults())
24+
.href("../%s".formatted(action.getUrlName()))
25+
.tooltip("Passed: %s%nFailed: %s%nSkipped: %s%nTotal: %s"
26+
.formatted(
27+
action.getTotalCount() - action.getFailCount() - action.getSkipCount(),
28+
action.getFailCount(),
29+
action.getSkipCount(),
30+
action.getTotalCount()))
31+
.build();
32+
return Optional.of(testResult);
33+
}
34+
35+
return Optional.empty();
36+
}
37+
}

src/main/java/io/jenkins/plugins/pipelinegraphview/consoleview/PipelineConsoleViewAction.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.jenkins.plugins.pipelinegraphview.cards.RunDetailsCard;
99
import io.jenkins.plugins.pipelinegraphview.cards.RunDetailsItem;
1010
import io.jenkins.plugins.pipelinegraphview.cards.items.SCMRunDetailsItems;
11+
import io.jenkins.plugins.pipelinegraphview.cards.items.TestResultRunDetailsItems;
1112
import io.jenkins.plugins.pipelinegraphview.cards.items.TimingRunDetailsItems;
1213
import io.jenkins.plugins.pipelinegraphview.cards.items.UpstreamCauseRunDetailsItem;
1314
import io.jenkins.plugins.pipelinegraphview.cards.items.UserIdCauseRunDetailsItem;
@@ -274,9 +275,7 @@ private static long parseIntWithDefault(String s, long defaultValue) {
274275
@SuppressWarnings("unused")
275276
public RunDetailsCard getRunDetailsCard() {
276277

277-
List<RunDetailsItem> runDetailsItems = new ArrayList<>();
278-
279-
runDetailsItems.addAll(SCMRunDetailsItems.get(run));
278+
List<RunDetailsItem> runDetailsItems = new ArrayList<>(SCMRunDetailsItems.get(run));
280279

281280
if (!runDetailsItems.isEmpty()) {
282281
runDetailsItems.add(new RunDetailsItem.Builder().separator().build());
@@ -287,6 +286,8 @@ public RunDetailsCard getRunDetailsCard() {
287286

288287
runDetailsItems.addAll(TimingRunDetailsItems.get(run));
289288

289+
TestResultRunDetailsItems.get(run).ifPresent(runDetailsItems::add);
290+
290291
return new RunDetailsCard(runDetailsItems);
291292
}
292293

Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
# The MIT License
2-
#
3-
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
4-
#
5-
# Permission is hereby granted, free of charge, to any person obtaining a copy
6-
# of this software and associated documentation files (the "Software"), to deal
7-
# in the Software without restriction, including without limitation the rights
8-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
# copies of the Software, and to permit persons to whom the Software is
10-
# furnished to do so, subject to the following conditions:
11-
#
12-
# The above copyright notice and this permission notice shall be included in
13-
# all copies or substantial portions of the Software.
14-
#
15-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
# THE SOFTWARE.
22-
231
startedAgo=Started {0} ago
242
noBuilds=No builds
253

@@ -33,3 +11,5 @@ timings.hour ={0} hr
3311
timings.day ={0} {0,choice,0#days|1#day|1<days}
3412
timings.month ={0} mo
3513
timings.year ={0} yr
14+
15+
testResults=Test results

src/main/resources/io/jenkins/plugins/pipelinegraphview/consoleview/PipelineConsoleViewAction/index.jelly

+12-10
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,20 @@
4747
<j:if test="${!card.separator}">
4848
<div>
4949
<l:icon src="${card.icon}"/>
50-
<j:choose>
51-
<j:when test="${!empty(card.href)}">
52-
<a
50+
<span tooltip="${card.tooltip}">
51+
<j:choose>
52+
<j:when test="${!empty(card.href)}">
53+
<a
5354
href="${card.href}"
54-
>
55+
>
56+
${card.text}
57+
</a>
58+
</j:when>
59+
<j:otherwise>
5560
${card.text}
56-
</a>
57-
</j:when>
58-
<j:otherwise>
59-
${card.text}
60-
</j:otherwise>
61-
</j:choose>
61+
</j:otherwise>
62+
</j:choose>
63+
</span>
6264
</div>
6365
</j:if>
6466
</j:forEach>

0 commit comments

Comments
 (0)