Skip to content

Commit

Permalink
Ensure message to check api is under 64kb (#193)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Jacomb <[email protected]>
  • Loading branch information
babusekaran and timja authored Oct 25, 2020
1 parent 2d41242 commit 12582a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
public class JUnitChecksPublisher {
public static final String SEPARATOR = ", ";

// arbitrary cap to avoid hitting any API limits and to limit the size of the page
// can be tuned based on feedback
private static final int MAX_RESULTS_TO_SEND_TO_CHECKS_API = 10;
// cap to avoid hitting check API message limit
private static final int MAX_MSG_SIZE_TO_CHECKS_API = 65535;
private final TestResultAction action;
private final TestResultSummary summary;

Expand Down Expand Up @@ -59,24 +58,26 @@ private String extractChecksText(String testsURL) {
StringBuilder builder = new StringBuilder();
if (summary.getFailCount() > 0) {
List<CaseResult> failedTests = action.getResult().getFailedTests();

if (failedTests.size() > MAX_RESULTS_TO_SEND_TO_CHECKS_API) {
failedTests = failedTests.subList(0, MAX_RESULTS_TO_SEND_TO_CHECKS_API - 1);
}

failedTests.forEach(failedTest -> mapFailedTestToTestReport(builder, failedTest));
if (summary.getFailCount() > MAX_RESULTS_TO_SEND_TO_CHECKS_API) {
builder.append("\n")
.append(summary.getFailCount() - MAX_RESULTS_TO_SEND_TO_CHECKS_API)
.append(" more test results are not shown here, view them on [Jenkins](")
.append(testsURL).append(")");

for (CaseResult failedTest: failedTests) {
String testReport = mapFailedTestToTestReport(failedTest);
int messageSize = testReport.length() + builder.toString().length();
// to ensure text size is withing check API message limit
if (messageSize > (MAX_MSG_SIZE_TO_CHECKS_API - 1024)){
builder.append("\n")
.append("more test results are not shown here, view them on [Jenkins](")
.append(testsURL).append(")");
break;
}
builder.append(testReport);
}
}

return builder.toString();
}

private void mapFailedTestToTestReport(StringBuilder builder, CaseResult failedTest) {
private String mapFailedTestToTestReport(CaseResult failedTest) {
StringBuilder builder = new StringBuilder();
builder.append("## `").append(failedTest.getTransformedFullDisplayName().trim()).append("`")
.append("\n");

Expand All @@ -102,6 +103,7 @@ private void mapFailedTestToTestReport(StringBuilder builder, CaseResult failedT
.append("</details>\n");
}
builder.append("\n");
return builder.toString();
}

private String codeTextFencedBlock(String body) {
Expand Down

0 comments on commit 12582a3

Please sign in to comment.