|
12 | 12 | import io.jenkins.plugins.checks.api.ChecksPublisher;
|
13 | 13 | import io.jenkins.plugins.checks.api.ChecksPublisherFactory;
|
14 | 14 | import io.jenkins.plugins.checks.api.ChecksStatus;
|
| 15 | +import io.jenkins.plugins.checks.api.TruncatedString; |
15 | 16 | import org.apache.commons.lang.StringUtils;
|
16 | 17 | import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
|
17 | 18 | import org.kohsuke.accmod.Restricted;
|
|
23 | 24 | public class JUnitChecksPublisher {
|
24 | 25 | public static final String SEPARATOR = ", ";
|
25 | 26 |
|
26 |
| - // cap to avoid hitting check API message limit |
27 |
| - private static final int MAX_MSG_SIZE_TO_CHECKS_API = 65535; |
28 | 27 | private final Run run;
|
29 | 28 | private final String checksName;
|
30 | 29 | private final TestResult result;
|
@@ -60,26 +59,17 @@ ChecksDetails extractChecksDetails() {
|
60 | 59 | .build();
|
61 | 60 | }
|
62 | 61 |
|
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 | + |
65 | 66 | 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); |
80 | 70 | }
|
81 | 71 |
|
82 |
| - return builder.toString(); |
| 72 | + return builder.build(); |
83 | 73 | }
|
84 | 74 |
|
85 | 75 | private String mapFailedTestToTestReport(CaseResult failedTest) {
|
|
0 commit comments