Skip to content

Commit

Permalink
Added time build took to the message
Browse files Browse the repository at this point in the history
Bumped version number to 2.1.1
  • Loading branch information
jasonconnery committed Mar 28, 2014
1 parent c62c636 commit 0536eb5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'java'


sourceCompatibility = 1.5
version = '2.0.0'
version = '2.1.1'

configurations {
deploy
Expand All @@ -17,7 +17,9 @@ dependencies {
compile files('libs/openapi.jar', 'libs/server-api.jar' , 'libs/common-api.jar' , 'libs/servlet-api.jar')
compile 'com.google.code.gson:gson:2.+'
compile 'org.jdom:jdom:1+'
compile 'joda-time:joda-time:2.3'
deploy 'com.google.code.gson:gson:2.+'
deploy 'joda-time:joda-time:2.3'

}

Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/tapadoo/slacknotifier/SlackServerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import jetbrains.buildServer.users.SUser;
import jetbrains.buildServer.users.UserSet;
import jetbrains.buildServer.vcs.SelectPrevBuildPolicy;
import org.joda.time.Duration;
import org.joda.time.Period;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;

import java.io.BufferedOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -124,10 +128,25 @@ else if( projectSettings != null && projectSettings.getChannel() != null && proj

String message = "";

PeriodFormatter durationFormatter = new PeriodFormatterBuilder()
.printZeroRarelyFirst()
.appendHours()
.appendSuffix(" hour", " hours")
.appendSeparator(" ")
.printZeroRarelyLast()
.appendMinutes()
.appendSuffix(" minute", "minutes")
.appendSeparator(" and ")
.appendSeconds()
.appendSuffix(" second", " seconds")
.toFormatter();

Duration buildDuration = new Duration(1000*build.getDuration());

JsonObject payloadObj = new JsonObject();
payloadObj.addProperty("channel" , channel);
payloadObj.addProperty("username" , "TeamCity");
payloadObj.addProperty("text", String.format("Project '%s' built successfully." , build.getFullName()));
payloadObj.addProperty("text", String.format("Project '%s' built successfully in %s." , build.getFullName() , durationFormatter.print(buildDuration.toPeriod())));
payloadObj.addProperty("icon_url",slackConfig.getLogoUrl());

if( commitMsg.length() > 0 )
Expand Down
2 changes: 1 addition & 1 deletion teamcity-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<info>
<name>slackNotifier</name> <!-- the name of plugin used in teamcity -->
<display-name>Slack Notifier</display-name>
<version>2.0.0</version>
<version>2.1.1</version>
<description>Post build success notifications to Slack</description>
<vendor>
<name>Tapadoo</name>
Expand Down

0 comments on commit 0536eb5

Please sign in to comment.