Skip to content

Commit

Permalink
#108 Fail gracefully when email-ext is not installed during card gene…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
aldaris committed Jul 20, 2017
1 parent 69cd0a5 commit fba9ab0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/main/java/jenkins/plugins/hipchat/impl/DefaultCardProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,31 @@ public Card getCard(Run<?, ?> run, TaskListener taskListener, Icon icon, String
}

private List<Attribute> getAttributes(Run<?, ?> run, TaskListener taskListener)
throws MacroEvaluationException, IOException, InterruptedException {
throws IOException, InterruptedException {
List<Attribute> ret = new ArrayList<>();
if (run.getAction(AbstractTestResultAction.class) != null) {
String count = TokenMacro.expand(run, null, taskListener, SUCCESS_TEST_COUNT_MACRO);
if (StringUtils.isNotEmpty(count)) {
ret.add(attribute(Messages.TestsSuccessful(), count,
"0".equals(count) ? LOZENGE_ERROR : LOZENGE_SUCCESS, null));
}
count = TokenMacro.expand(run, null, taskListener, FAILED_TEST_COUNT_MACRO);
if (StringUtils.isNotEmpty(count)) {
ret.add(attribute(Messages.TestsFailed(), count,
"0".equals(count) ? LOZENGE_SUCCESS : LOZENGE_ERROR, null));
}
count = TokenMacro.expand(run, null, taskListener, SKIPPED_TEST_COUNT_MACRO);
if (StringUtils.isNotEmpty(count)) {
ret.add(attribute(Messages.TestsSkipped(), count,
"0".equals(count) ? LOZENGE_SUCCESS : LOZENGE_CURRENT, null));
}
if (!ret.isEmpty()) {
ret.add(attribute(Messages.TestReport(), Messages.Here(), null,
TokenMacro.expand(run, null, taskListener, TEST_REPORT_URL_MACRO)));
try {
String count = TokenMacro.expand(run, null, taskListener, SUCCESS_TEST_COUNT_MACRO);
if (StringUtils.isNotEmpty(count)) {
ret.add(attribute(Messages.TestsSuccessful(), count,
"0".equals(count) ? LOZENGE_ERROR : LOZENGE_SUCCESS, null));
}
count = TokenMacro.expand(run, null, taskListener, FAILED_TEST_COUNT_MACRO);
if (StringUtils.isNotEmpty(count)) {
ret.add(attribute(Messages.TestsFailed(), count,
"0".equals(count) ? LOZENGE_SUCCESS : LOZENGE_ERROR, null));
}
count = TokenMacro.expand(run, null, taskListener, SKIPPED_TEST_COUNT_MACRO);
if (StringUtils.isNotEmpty(count)) {
ret.add(attribute(Messages.TestsSkipped(), count,
"0".equals(count) ? LOZENGE_SUCCESS : LOZENGE_CURRENT, null));
}
if (!ret.isEmpty()) {
ret.add(attribute(Messages.TestReport(), Messages.Here(), null,
TokenMacro.expand(run, null, taskListener, TEST_REPORT_URL_MACRO)));
}
} catch (MacroEvaluationException mee) {
taskListener.getLogger().println(Messages.UnresolvedMacro(mee.getMessage()));
}
}
return ret.isEmpty() ? null : ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ InvalidResponseCode=Unexpected response code from HipChat: {0}
IOException=Unexpected IO error occurred while sending notification: {0}
MacroEvaluationFailed=[ERROR] Failed to evaluate tokens in the provided message template due to: {0}
NotificationFailed=[ERROR] HipChat notification failed with error message: {0}
UnresolvedMacro=[WARNING] An error occurred while trying to resolve a macro for the HipChat card: {0}

# Error Messages
MessageRequiredError=HipChat message not sent. Message property must be supplied.

0 comments on commit fba9ab0

Please sign in to comment.