diff --git a/build.gradle b/build.gradle index cb3f1a7..9fbaafd 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ apply plugin: 'java' sourceCompatibility = 1.8 -version = '4.0.2' +version = '4.1.1' configurations { deploy diff --git a/src/main/java/com/tapadoo/slacknotifier/SlackServerAdapter.java b/src/main/java/com/tapadoo/slacknotifier/SlackServerAdapter.java index 7fd0991..9c5edd7 100644 --- a/src/main/java/com/tapadoo/slacknotifier/SlackServerAdapter.java +++ b/src/main/java/com/tapadoo/slacknotifier/SlackServerAdapter.java @@ -183,24 +183,6 @@ else if( projectSettings != null && projectSettings.getChannel() != null && proj UserSet committers = build.getCommitters(SelectPrevBuildPolicy.SINCE_LAST_BUILD); StringBuilder committersString = new StringBuilder(); - List changes = build.getChanges(SelectPrevBuildPolicy.SINCE_LAST_SUCCESSFULLY_FINISHED_BUILD, true); - - StringBuilder commitMessage = new StringBuilder(); - - /* - * If this field starts to feel too long in slack, we should only use the first item in the array, which would be the latest change - * - */ - for ( int i = 0 ; i < changes.size() ; i++ ){ - SVcsModification modification = changes.get(i); - String desc = modification.getDescription(); - commitMessage.append(desc); - - if( i < changes.size() - 1 ) { - commitMessage.append("\n------\n"); - } - } - for( SUser committer : committers.getUsers() ) { if( committer != null) @@ -314,21 +296,14 @@ else if( projectSettings != null && projectSettings.getChannel() != null && proj fallbackMessage.append(issueIds.toString()); } - /* TODO: Consider adding a setting to SlackProjectSettings perhaps to enable / disable commit messages at a project level? */ - if( commitMessage.length() > 0 ) { - JsonObject field = new JsonObject() ; - - field.addProperty("title", "Commit Messages"); - field.addProperty("value",commitMessage.toString()); - field.addProperty("short", false); - - fields.add(field); - } - attachment.addProperty("color", (goodColor ? "good" : "danger")); + attachment.add("fields",fields); + JsonObject commitAttachment = createCommitAttachment(build); - attachment.add("fields",fields); + if(commitAttachment != null) { + attachmentsObj.add(commitAttachment); + } if( attachmentsObj.size() > 0 ) { payloadObj.add("attachments", attachmentsObj); @@ -360,4 +335,40 @@ else if( projectSettings != null && projectSettings.getChannel() != null && proj } } + private JsonObject createCommitAttachment(SRunningBuild build) { + + List changes = build.getChanges(SelectPrevBuildPolicy.SINCE_LAST_SUCCESSFULLY_FINISHED_BUILD, true); + + StringBuilder commitMessage = new StringBuilder(); + + /* + * If this field starts to feel too long in slack, we should only use the first item in the array, which would be the latest change + * + */ + for ( int i = 0 ; i < changes.size() ; i++ ){ + SVcsModification modification = changes.get(i); + String desc = modification.getDescription(); + commitMessage.append("‣ "); + commitMessage.append(desc); + + if( i < changes.size() - 1 ) { + commitMessage.append("\n"); + } + } + + if (changes.size() < 1) { + return null; + } + + String commitMessageString = commitMessage.toString(); + JsonObject attachment = new JsonObject(); + attachment.addProperty("title", "Commit Messages"); + attachment.addProperty("fallback" , commitMessageString); + attachment.addProperty("text" , commitMessageString); + attachment.addProperty("color" , "#2FA8B9"); + + return attachment; + + } + } diff --git a/teamcity-plugin.xml b/teamcity-plugin.xml index 8bc51f7..3396610 100644 --- a/teamcity-plugin.xml +++ b/teamcity-plugin.xml @@ -4,7 +4,7 @@ slackNotifier Slack Notifier - 4.0.2 + 4.1.1 Post build success notifications to Slack Tapadoo