From a8dabe0ce5348634b23c5d6f983905c35a73b84f Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Sat, 29 Oct 2016 13:24:53 -0700 Subject: [PATCH 1/2] Add display-console-logs option. --- README.md | 2 ++ docs/index.md | 2 ++ .../gocd/slack/SlackPipelineListener.java | 5 +++-- .../ashwanthkumar/gocd/slack/ruleset/Rules.java | 16 ++++++++++++++++ src/main/resources/reference.conf | 4 ++++ .../gocd/slack/ruleset/RulesReaderTest.java | 2 ++ src/test/resources/configs/test-config-1.conf | 2 ++ 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad5ca1c..647a983 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ gocd.slack { channel = "#build" slackDisplayName = "gocd-slack-bot" slackUserIconURL = "http://example.com/slack-bot.png" + display-console-logs = true displayMaterialChanges = true process-all-rules = true proxy { @@ -40,6 +41,7 @@ gocd.slack { - `api-server-host` - This is an optional attribute. Set this field to localhost so server will use this endpoint to get `PipelineHistory` and `PipelineInstance` - `webhookUrl` - Slack Webhook URL - `channel` - Override the default channel where we should send the notifications in slack. You can also give a value starting with `@` to send it to any specific user. +- `display-console-logs` - Display console logs in the notification. Defaults to true, set to false if you want to hide. - `displayMaterialChanges` - Display material changes in the notification (git revisions for example). Defaults to true, set to false if you want to hide. - `process-all-rules` - If true, all matching rules are applied instead of just the first. - `proxy` - Specify proxy related settings for the plugin. diff --git a/docs/index.md b/docs/index.md index a79bcde..1bbef66 100644 --- a/docs/index.md +++ b/docs/index.md @@ -25,6 +25,7 @@ gocd.slack { channel = "#build" slackDisplayName = "gocd-slack-bot" slackUserIconURL = "http://example.com/slack-bot.png" + display-console-logs = true displayMaterialChanges = true process-all-rules = true proxy { @@ -40,6 +41,7 @@ gocd.slack { - `api-server-host` - This is an optional attribute. Set this field to localhost so server will use this endpoint to get `PipelineHistory` and `PipelineInstance` - `webhookUrl` - Slack Webhook URL - `channel` - Override the default channel where we should send the notifications in slack. You can also give a value starting with `@` to send it to any specific user. +- `display-console-logs` - Display console logs in the notification. Defaults to true, set to false if you want to hide. - `displayMaterialChanges` - Display material changes in the notification (git revisions for example). Defaults to true, set to false if you want to hide. - `process-all-rules` - If true, all matching rules are applied instead of just the first. - `proxy` - Specify proxy related settings for the plugin. diff --git a/src/main/java/in/ashwanthkumar/gocd/slack/SlackPipelineListener.java b/src/main/java/in/ashwanthkumar/gocd/slack/SlackPipelineListener.java index 817bf33..0ab2b46 100644 --- a/src/main/java/in/ashwanthkumar/gocd/slack/SlackPipelineListener.java +++ b/src/main/java/in/ashwanthkumar/gocd/slack/SlackPipelineListener.java @@ -97,7 +97,9 @@ private SlackAttachment slackAttachment(PipelineRule rule, GoNotificationMessage buildAttachment.addField(new SlackAttachment.Field("Reason", details.buildCause.triggerMessage, true)); } buildAttachment.addField(new SlackAttachment.Field("Label", details.label, true)); - consoleLogLinks = createConsoleLogLinks(rules.getGoServerHost(), details, stage, pipelineStatus); + if (rules.getDisplayConsoleLogs()) { + consoleLogLinks = createConsoleLogLinks(rules.getGoServerHost(), details, stage, pipelineStatus); + } } catch (Exception e) { buildAttachment.text("(Couldn't fetch build details; see server log.) "); LOG.warn("Couldn't fetch build details", e); @@ -144,7 +146,6 @@ private SlackAttachment slackAttachment(PipelineRule rule, GoNotificationMessage } } - if (!consoleLogLinks.isEmpty()) { String logLinks = Lists.mkString(consoleLogLinks, "", "", "\n"); buildAttachment.addField(new SlackAttachment.Field("Console Logs", logLinks, true)); diff --git a/src/main/java/in/ashwanthkumar/gocd/slack/ruleset/Rules.java b/src/main/java/in/ashwanthkumar/gocd/slack/ruleset/Rules.java index 080dc03..1524b27 100644 --- a/src/main/java/in/ashwanthkumar/gocd/slack/ruleset/Rules.java +++ b/src/main/java/in/ashwanthkumar/gocd/slack/ruleset/Rules.java @@ -29,6 +29,7 @@ public class Rules { private String goAPIServerHost; private String goLogin; private String goPassword; + private boolean displayConsoleLogs; private boolean displayMaterialChanges; private boolean processAllRules; @@ -131,6 +132,15 @@ public Rules setGoPassword(String goPassword) { return this; } + public boolean getDisplayConsoleLogs() { + return displayConsoleLogs; + } + + public Rules setDisplayConsoleLogs(boolean displayConsoleLogs) { + this.displayConsoleLogs = displayConsoleLogs; + return this; + } + public boolean getDisplayMaterialChanges() { return displayMaterialChanges; } @@ -214,6 +224,11 @@ public static Rules fromConfig(Config config) { password = config.getString("password"); } + boolean displayConsoleLogs = true; + if (config.hasPath("display-console-logs")) { + displayConsoleLogs = config.getBoolean("display-console-logs"); + } + // TODO - Next major release - change this to - separated config boolean displayMaterialChanges = true; if (config.hasPath("displayMaterialChanges")) { @@ -256,6 +271,7 @@ public PipelineRule apply(Config input) { .setGoAPIServerHost(apiServerHost) .setGoLogin(login) .setGoPassword(password) + .setDisplayConsoleLogs(displayConsoleLogs) .setDisplayMaterialChanges(displayMaterialChanges) .setProcessAllRules(processAllRules) .setProxy(proxy); diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index da44577..277e81f 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -17,6 +17,10 @@ gocd.slack { # Setup up an incoming webhook in your slack team on https://my.slack.com/services/new/incoming-webhook/ #webhookUrl: "" # Mandatory field + # If you don't want to see the console logs in the notification (for size concerns). + # Defaults to true. + #display-console-logs = true + # If you don't want to see the revision changes in the notification (for size or confidentiality concerns) # defaults to true #displayMaterialChanges = true diff --git a/src/test/java/in/ashwanthkumar/gocd/slack/ruleset/RulesReaderTest.java b/src/test/java/in/ashwanthkumar/gocd/slack/ruleset/RulesReaderTest.java index cf0417c..a0cd4fd 100644 --- a/src/test/java/in/ashwanthkumar/gocd/slack/ruleset/RulesReaderTest.java +++ b/src/test/java/in/ashwanthkumar/gocd/slack/ruleset/RulesReaderTest.java @@ -19,6 +19,7 @@ public void shouldReadTestConfig() { assertThat(rules.getGoServerHost(), is("http://localhost:8080/")); assertThat(rules.getPipelineRules().size(), is(2)); assertThat(rules.getPipelineRules().size(), is(2)); + assertThat(rules.getDisplayConsoleLogs(), is(false)); assertThat(rules.getDisplayMaterialChanges(), is(false)); PipelineRule pipelineRule1 = new PipelineRule() @@ -55,6 +56,7 @@ public void shouldReadMinimalConfig() { // Default rules assertThat(rules.getPipelineRules().size(), is(1)); + assertThat(rules.getDisplayConsoleLogs(), is(true)); assertThat(rules.getDisplayMaterialChanges(), is(true)); PipelineRule pipelineRule = new PipelineRule() diff --git a/src/test/resources/configs/test-config-1.conf b/src/test/resources/configs/test-config-1.conf index 2ecd974..a24bf31 100644 --- a/src/test/resources/configs/test-config-1.conf +++ b/src/test/resources/configs/test-config-1.conf @@ -8,6 +8,8 @@ gocd.slack { # Enter full FQDN of your GoCD instance. We'll be sending links on your slack channel using this as the base uri. server-host = "http://localhost:8080/" + display-console-logs = false + # If you don't want to see the revision changes in the notification (for size or confidentiality concerns) # defaults to true displayMaterialChanges = false From 8ccb5771cf761ea426ef959abd2b4708bedca4d2 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Sun, 30 Oct 2016 06:41:54 -0700 Subject: [PATCH 2/2] Rename display-console-logs to display-console-log-links. --- README.md | 4 ++-- docs/index.md | 4 ++-- .../gocd/slack/SlackPipelineListener.java | 2 +- .../gocd/slack/ruleset/Rules.java | 18 +++++++++--------- src/main/resources/reference.conf | 4 ++-- .../gocd/slack/ruleset/RulesReaderTest.java | 4 ++-- src/test/resources/configs/test-config-1.conf | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 647a983..6552c34 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ gocd.slack { channel = "#build" slackDisplayName = "gocd-slack-bot" slackUserIconURL = "http://example.com/slack-bot.png" - display-console-logs = true + display-console-log-links = true displayMaterialChanges = true process-all-rules = true proxy { @@ -41,7 +41,7 @@ gocd.slack { - `api-server-host` - This is an optional attribute. Set this field to localhost so server will use this endpoint to get `PipelineHistory` and `PipelineInstance` - `webhookUrl` - Slack Webhook URL - `channel` - Override the default channel where we should send the notifications in slack. You can also give a value starting with `@` to send it to any specific user. -- `display-console-logs` - Display console logs in the notification. Defaults to true, set to false if you want to hide. +- `display-console-log-links` - Display console log links in the notification. Defaults to true, set to false if you want to hide. - `displayMaterialChanges` - Display material changes in the notification (git revisions for example). Defaults to true, set to false if you want to hide. - `process-all-rules` - If true, all matching rules are applied instead of just the first. - `proxy` - Specify proxy related settings for the plugin. diff --git a/docs/index.md b/docs/index.md index 1bbef66..b1ccad0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -25,7 +25,7 @@ gocd.slack { channel = "#build" slackDisplayName = "gocd-slack-bot" slackUserIconURL = "http://example.com/slack-bot.png" - display-console-logs = true + display-console-log-links = true displayMaterialChanges = true process-all-rules = true proxy { @@ -41,7 +41,7 @@ gocd.slack { - `api-server-host` - This is an optional attribute. Set this field to localhost so server will use this endpoint to get `PipelineHistory` and `PipelineInstance` - `webhookUrl` - Slack Webhook URL - `channel` - Override the default channel where we should send the notifications in slack. You can also give a value starting with `@` to send it to any specific user. -- `display-console-logs` - Display console logs in the notification. Defaults to true, set to false if you want to hide. +- `display-console-log-links` - Display console log links in the notification. Defaults to true, set to false if you want to hide. - `displayMaterialChanges` - Display material changes in the notification (git revisions for example). Defaults to true, set to false if you want to hide. - `process-all-rules` - If true, all matching rules are applied instead of just the first. - `proxy` - Specify proxy related settings for the plugin. diff --git a/src/main/java/in/ashwanthkumar/gocd/slack/SlackPipelineListener.java b/src/main/java/in/ashwanthkumar/gocd/slack/SlackPipelineListener.java index 0ab2b46..fd14048 100644 --- a/src/main/java/in/ashwanthkumar/gocd/slack/SlackPipelineListener.java +++ b/src/main/java/in/ashwanthkumar/gocd/slack/SlackPipelineListener.java @@ -97,7 +97,7 @@ private SlackAttachment slackAttachment(PipelineRule rule, GoNotificationMessage buildAttachment.addField(new SlackAttachment.Field("Reason", details.buildCause.triggerMessage, true)); } buildAttachment.addField(new SlackAttachment.Field("Label", details.label, true)); - if (rules.getDisplayConsoleLogs()) { + if (rules.getDisplayConsoleLogLinks()) { consoleLogLinks = createConsoleLogLinks(rules.getGoServerHost(), details, stage, pipelineStatus); } } catch (Exception e) { diff --git a/src/main/java/in/ashwanthkumar/gocd/slack/ruleset/Rules.java b/src/main/java/in/ashwanthkumar/gocd/slack/ruleset/Rules.java index 1524b27..9d0dd37 100644 --- a/src/main/java/in/ashwanthkumar/gocd/slack/ruleset/Rules.java +++ b/src/main/java/in/ashwanthkumar/gocd/slack/ruleset/Rules.java @@ -29,7 +29,7 @@ public class Rules { private String goAPIServerHost; private String goLogin; private String goPassword; - private boolean displayConsoleLogs; + private boolean displayConsoleLogLinks; private boolean displayMaterialChanges; private boolean processAllRules; @@ -132,12 +132,12 @@ public Rules setGoPassword(String goPassword) { return this; } - public boolean getDisplayConsoleLogs() { - return displayConsoleLogs; + public boolean getDisplayConsoleLogLinks() { + return displayConsoleLogLinks; } - public Rules setDisplayConsoleLogs(boolean displayConsoleLogs) { - this.displayConsoleLogs = displayConsoleLogs; + public Rules setDisplayConsoleLogLinks(boolean displayConsoleLogLinks) { + this.displayConsoleLogLinks = displayConsoleLogLinks; return this; } @@ -224,9 +224,9 @@ public static Rules fromConfig(Config config) { password = config.getString("password"); } - boolean displayConsoleLogs = true; - if (config.hasPath("display-console-logs")) { - displayConsoleLogs = config.getBoolean("display-console-logs"); + boolean displayConsoleLogLinks = true; + if (config.hasPath("display-console-log-links")) { + displayConsoleLogLinks = config.getBoolean("display-console-log-links"); } // TODO - Next major release - change this to - separated config @@ -271,7 +271,7 @@ public PipelineRule apply(Config input) { .setGoAPIServerHost(apiServerHost) .setGoLogin(login) .setGoPassword(password) - .setDisplayConsoleLogs(displayConsoleLogs) + .setDisplayConsoleLogLinks(displayConsoleLogLinks) .setDisplayMaterialChanges(displayMaterialChanges) .setProcessAllRules(processAllRules) .setProxy(proxy); diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 277e81f..64b01be 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -17,9 +17,9 @@ gocd.slack { # Setup up an incoming webhook in your slack team on https://my.slack.com/services/new/incoming-webhook/ #webhookUrl: "" # Mandatory field - # If you don't want to see the console logs in the notification (for size concerns). + # If you don't want to see the console log links in the notification (for size concerns). # Defaults to true. - #display-console-logs = true + #display-console-log-links = true # If you don't want to see the revision changes in the notification (for size or confidentiality concerns) # defaults to true diff --git a/src/test/java/in/ashwanthkumar/gocd/slack/ruleset/RulesReaderTest.java b/src/test/java/in/ashwanthkumar/gocd/slack/ruleset/RulesReaderTest.java index a0cd4fd..74c3713 100644 --- a/src/test/java/in/ashwanthkumar/gocd/slack/ruleset/RulesReaderTest.java +++ b/src/test/java/in/ashwanthkumar/gocd/slack/ruleset/RulesReaderTest.java @@ -19,7 +19,7 @@ public void shouldReadTestConfig() { assertThat(rules.getGoServerHost(), is("http://localhost:8080/")); assertThat(rules.getPipelineRules().size(), is(2)); assertThat(rules.getPipelineRules().size(), is(2)); - assertThat(rules.getDisplayConsoleLogs(), is(false)); + assertThat(rules.getDisplayConsoleLogLinks(), is(false)); assertThat(rules.getDisplayMaterialChanges(), is(false)); PipelineRule pipelineRule1 = new PipelineRule() @@ -56,7 +56,7 @@ public void shouldReadMinimalConfig() { // Default rules assertThat(rules.getPipelineRules().size(), is(1)); - assertThat(rules.getDisplayConsoleLogs(), is(true)); + assertThat(rules.getDisplayConsoleLogLinks(), is(true)); assertThat(rules.getDisplayMaterialChanges(), is(true)); PipelineRule pipelineRule = new PipelineRule() diff --git a/src/test/resources/configs/test-config-1.conf b/src/test/resources/configs/test-config-1.conf index a24bf31..f06c800 100644 --- a/src/test/resources/configs/test-config-1.conf +++ b/src/test/resources/configs/test-config-1.conf @@ -8,7 +8,7 @@ gocd.slack { # Enter full FQDN of your GoCD instance. We'll be sending links on your slack channel using this as the base uri. server-host = "http://localhost:8080/" - display-console-logs = false + display-console-log-links = false # If you don't want to see the revision changes in the notification (for size or confidentiality concerns) # defaults to true