Skip to content

Commit

Permalink
Fix empty message issues
Browse files Browse the repository at this point in the history
When there is no config set there was an empty message being sent,
instead make sure the defaults are used.
  • Loading branch information
Marcin Szczepanski committed Feb 9, 2013
1 parent 2e33605 commit 333d376
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java
Expand Up @@ -50,11 +50,10 @@ public void started(AbstractBuild build) {
messageParams.put("changes", changes); messageParams.put("changes", changes);
messageParams.put("link", MessageBuilder.getOpenLink(notifier, build)); messageParams.put("link", MessageBuilder.getOpenLink(notifier, build));


if (notifier.getMessageTemplateStarted() == null) if (notifier.getMessageTemplateStarted() == null || "".equals(notifier.getMessageTemplateStarted()))
{ {
logger.warning("Started message template is not set!"); logger.warning("Started message template is not set, using default");
notifier.setMessageTemplateStarted("{{build.project.displayName}} - {{build.displayName}}: Started {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}"); notifier.setMessageTemplateStarted("{{build.project.displayName}} - {{build.displayName}}: Started {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}");
return;
} }


notifyStart(build, applyMessageTemplate(notifier.getMessageTemplateStarted(), messageParams)); notifyStart(build, applyMessageTemplate(notifier.getMessageTemplateStarted(), messageParams));
Expand All @@ -78,9 +77,9 @@ public void completed(AbstractBuild r) {
|| (result == Result.SUCCESS && jobProperty.getNotifySuccess()) || (result == Result.SUCCESS && jobProperty.getNotifySuccess())
|| (result == Result.UNSTABLE && jobProperty.getNotifyUnstable())) { || (result == Result.UNSTABLE && jobProperty.getNotifyUnstable())) {


if (notifier.getMessageTemplateCompleted() == null) if (notifier.getMessageTemplateCompleted() == null || "".equals(notifier.getMessageTemplateCompleted()))
{ {
logger.warning("Completed message template is not set!"); logger.warning("Completed message template is not set, using default");
notifier.setMessageTemplateCompleted("{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}} {{{link}}}"); notifier.setMessageTemplateCompleted("{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}} {{{link}}}");
} }


Expand Down

2 comments on commit 333d376

@phil-schneider
Copy link

Choose a reason for hiding this comment

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

Please use StringUtils.isBlank for checking if a string is .
I would also change the logger from warning to info.
Warning means: do something or it will might lead to a bug.

@marcins
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the feedback - the warnings aren't there in the latest commit, but I've changed the way I check for blank strings.

Please sign in to comment.