Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Stack;
import java.util.logging.Level;
Expand Down Expand Up @@ -106,14 +107,20 @@ private Pair<String, String> processErrorOrWarningRow(final FlowGraphTable.Row r

nodeSummaryBuilder.append(String.format("### `%s`%n", String.join(" / ", location)));

nodeSummaryBuilder.append(String.format("%s in `%s` step", errorAction == null ? "Warning" : "Error",
flowNode.getDisplayFunctionName()));
String arguments = ArgumentsAction.getStepArgumentsAsString(flowNode);
if (arguments == null) {
nodeSummaryBuilder.append(".\n");
}
else {
nodeSummaryBuilder.append(String.format(", with arguments `%s`.%n", arguments));
if (errorAction != null && isTrivialErrorOrUnstable(flowNode, "error", errorAction.getDisplayName())
|| warningAction != null && isTrivialErrorOrUnstable(flowNode, "unstable", warningAction.getMessage())) {
// Suppress the step name and arguments because they
// would be mostly redundant with other text.
} else {
nodeSummaryBuilder.append(String.format("%s in `%s` step", errorAction == null ? "Warning" : "Error",
flowNode.getDisplayFunctionName()));
String arguments = ArgumentsAction.getStepArgumentsAsString(flowNode);
if (arguments == null) {
nodeSummaryBuilder.append(".\n");
}
else {
nodeSummaryBuilder.append(String.format(", with arguments `%s`.%n", arguments));
}
}

nodeTextBuilder.append(String.join("", Collections.nCopies(indentationStack.size() + 1, " ")));
Expand Down Expand Up @@ -175,16 +182,61 @@ ChecksOutput extractOutput() {
.build();
}

private String getPotentialTitle(final FlowNode flowNode, final ErrorAction errorAction) {
final String whereBuildFailed = String.format("%s in '%s' step", errorAction == null ? "warning" : "error",
flowNode.getDisplayFunctionName());
private String getPotentialTitle(@NonNull final FlowNode flowNode, final ErrorAction errorAction) {
String whereBuildFailed = null;
if (errorAction != null
&& isTrivialErrorOrUnstable(flowNode, "error", errorAction.getDisplayName())) {
whereBuildFailed = summarize(errorAction.getDisplayName());
}
if (whereBuildFailed == null) {
whereBuildFailed = String.format("%s in '%s' step", errorAction == null ? "warning" : "error",
flowNode.getDisplayFunctionName());
}

List<FlowNode> enclosingStagesAndParallels = getEnclosingStagesAndParallels(flowNode);
List<String> enclosingBlockNames = getEnclosingBlockNames(enclosingStagesAndParallels);

return StringUtils.join(new ReverseListIterator(enclosingBlockNames), "/") + ": " + whereBuildFailed;
}

/**
* Check whether the node is an "error" or "unstable" step with the
* specified message and no other arguments. In that case, the caller
* can simplify the output.
*
* @param node The flow node to examine.
* @param name The expected name of the step; either "error" or "unstable".
* @param message The error or warning that was reported from the node.
*/
private static boolean isTrivialErrorOrUnstable(@NonNull final FlowNode node,
@NonNull final String name,
final String message) {
if (node instanceof StepNode) {
StepDescriptor d = ((StepNode) node).getDescriptor();
if (d != null && d.getFunctionName().equals(name)) {
Map<String, Object> arguments = ArgumentsAction.getArguments(node);
if (arguments != null && arguments.size() == 1) {
Object argument = arguments.get("message");
return argument instanceof String
&& argument.equals(message);
}
}
}

return false;
}

private static String summarize(String message) {
if (message != null) {
final String firstLine = message.split("\r?\n", 2)[0];
if (!firstLine.isEmpty()) {
return firstLine;
Copy link

@justinmchase justinmchase Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a maximum length on here too in case the first line is something crazy long?

return firstLine.length > 256 ? firstLine.substr(0, 255) + "" : firstLine;

}
}

return null;
}

private static boolean isStageNode(@NonNull final FlowNode node) {
if (node instanceof StepNode) {
StepDescriptor d = ((StepNode) node).getDescriptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public void shouldPublishStageDetails() {
assertThat(output.getTitle()).isPresent().get().isEqualTo("In parallel/p1/p1s1: warning in 'unstable' step");
assertThat(output.getSummary()).isPresent().get().asString().isEqualToIgnoringNewLines(""
+ "### `In parallel / p1 / p1s1 / Set stage result to unstable`\n"
+ "Warning in `unstable` step, with arguments `something went wrong`.\n"
+ "```\n"
+ "something went wrong\n"
+ "```\n"
Expand All @@ -199,15 +198,13 @@ public void shouldPublishStageDetails() {
assertThat(details.getStatus()).isEqualTo(ChecksStatus.COMPLETED);
assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.FAILURE);
assertThat(details.getOutput()).isPresent().get().satisfies(output -> {
assertThat(output.getTitle()).isPresent().get().isEqualTo("Fails: error in 'error' step");
assertThat(output.getTitle()).isPresent().get().isEqualTo("Fails: a fatal error occurs");
assertThat(output.getSummary()).isPresent().get().asString().matches(Pattern.compile(".*"
+ "### `In parallel / p1 / p1s1 / Set stage result to unstable`\\s+"
+ "Warning in `unstable` step, with arguments `something went wrong`\\.\\s+"
+ "```\\s+"
+ "something went wrong\\s+"
+ "```\\s+"
+ "### `Fails / Error signal`\\s+"
+ "Error in `error` step, with arguments `a fatal error occurs`\\.\\s+"
+ "```\\s+"
+ "a fatal error occurs\\s+"
+ "```\\s+", Pattern.DOTALL));
Expand Down Expand Up @@ -267,7 +264,6 @@ public void shouldPublishStageDetailsWithoutLogsIfRequested() {
assertThat(output.getTitle()).isPresent().get().isEqualTo("Fails: error in 'archiveArtifacts' step");
assertThat(output.getSummary()).isPresent().get().asString().matches(Pattern.compile(".*"
+ "### `In parallel / p1 / p1s1 / Set stage result to unstable`\\s+"
+ "Warning in `unstable` step, with arguments `something went wrong`\\.\\s+"
+ "```\\s+"
+ "something went wrong\\s+"
+ "```\\s+"
Expand Down