Skip to content

Commit c959732

Browse files
committed
Use truncated strings from checks api
1 parent 0c6a43d commit c959732

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<java.level>8</java.level>
2121
<no-test-jar>false</no-test-jar>
2222
<configuration-as-code.version>1.46</configuration-as-code.version>
23-
<checks-api.version>1.2.0</checks-api.version>
23+
<checks-api.version>1.3.0-rc182.e92aa81c9bc8</checks-api.version>
2424
</properties>
2525
<licenses>
2626
<license>

src/main/java/io/jenkins/plugins/junit/checks/JUnitChecksPublisher.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.jenkins.plugins.checks.api.ChecksPublisher;
1313
import io.jenkins.plugins.checks.api.ChecksPublisherFactory;
1414
import io.jenkins.plugins.checks.api.ChecksStatus;
15+
import io.jenkins.plugins.checks.api.TruncatedString;
1516
import org.apache.commons.lang.StringUtils;
1617
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
1718
import org.kohsuke.accmod.Restricted;
@@ -23,8 +24,6 @@
2324
public class JUnitChecksPublisher {
2425
public static final String SEPARATOR = ", ";
2526

26-
// cap to avoid hitting check API message limit
27-
private static final int MAX_MSG_SIZE_TO_CHECKS_API = 65535;
2827
private final Run run;
2928
private final String checksName;
3029
private final TestResult result;
@@ -60,26 +59,17 @@ ChecksDetails extractChecksDetails() {
6059
.build();
6160
}
6261

63-
private String extractChecksText(String testsURL) {
64-
StringBuilder builder = new StringBuilder();
62+
private TruncatedString extractChecksText(String testsURL) {
63+
TruncatedString.Builder builder = new TruncatedString.Builder()
64+
.withTruncationText(String.format("\nmore test results are not shown here, view them on [Jenkins](%s)", testsURL));
65+
6566
if (summary.getFailCount() > 0) {
66-
List<CaseResult> failedTests = result.getFailedTests();
67-
68-
for (CaseResult failedTest: failedTests) {
69-
String testReport = mapFailedTestToTestReport(failedTest);
70-
int messageSize = testReport.length() + builder.toString().length();
71-
// to ensure text size is withing check API message limit
72-
if (messageSize > (MAX_MSG_SIZE_TO_CHECKS_API - 1024)){
73-
builder.append("\n")
74-
.append("more test results are not shown here, view them on [Jenkins](")
75-
.append(testsURL).append(")");
76-
break;
77-
}
78-
builder.append(testReport);
79-
}
67+
result.getFailedTests().stream()
68+
.map(this::mapFailedTestToTestReport)
69+
.forEach(builder::addText);
8070
}
8171

82-
return builder.toString();
72+
return builder.build();
8373
}
8474

8575
private String mapFailedTestToTestReport(CaseResult failedTest) {

0 commit comments

Comments
 (0)