Skip to content

Commit

Permalink
Merge pull request #59 from jdavisp3/display-console-logs
Browse files Browse the repository at this point in the history
Add display-console-logs option.
  • Loading branch information
ashwanthkumar authored Oct 30, 2016
2 parents b60f5dc + 8ccb577 commit 973ede0
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ gocd.slack {
channel = "#build"
slackDisplayName = "gocd-slack-bot"
slackUserIconURL = "http://example.com/slack-bot.png"
display-console-log-links = true
displayMaterialChanges = true
process-all-rules = true
proxy {
Expand All @@ -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-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.
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ gocd.slack {
channel = "#build"
slackDisplayName = "gocd-slack-bot"
slackUserIconURL = "http://example.com/slack-bot.png"
display-console-log-links = true
displayMaterialChanges = true
process-all-rules = true
proxy {
Expand All @@ -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-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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.getDisplayConsoleLogLinks()) {
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);
Expand Down Expand Up @@ -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));
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/in/ashwanthkumar/gocd/slack/ruleset/Rules.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Rules {
private String goAPIServerHost;
private String goLogin;
private String goPassword;
private boolean displayConsoleLogLinks;
private boolean displayMaterialChanges;
private boolean processAllRules;

Expand Down Expand Up @@ -131,6 +132,15 @@ public Rules setGoPassword(String goPassword) {
return this;
}

public boolean getDisplayConsoleLogLinks() {
return displayConsoleLogLinks;
}

public Rules setDisplayConsoleLogLinks(boolean displayConsoleLogLinks) {
this.displayConsoleLogLinks = displayConsoleLogLinks;
return this;
}

public boolean getDisplayMaterialChanges() {
return displayMaterialChanges;
}
Expand Down Expand Up @@ -214,6 +224,11 @@ public static Rules fromConfig(Config config) {
password = config.getString("password");
}

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
boolean displayMaterialChanges = true;
if (config.hasPath("displayMaterialChanges")) {
Expand Down Expand Up @@ -256,6 +271,7 @@ public PipelineRule apply(Config input) {
.setGoAPIServerHost(apiServerHost)
.setGoLogin(login)
.setGoPassword(password)
.setDisplayConsoleLogLinks(displayConsoleLogLinks)
.setDisplayMaterialChanges(displayMaterialChanges)
.setProcessAllRules(processAllRules)
.setProxy(proxy);
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 log links in the notification (for size concerns).
# Defaults to 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
#displayMaterialChanges = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.getDisplayConsoleLogLinks(), is(false));
assertThat(rules.getDisplayMaterialChanges(), is(false));

PipelineRule pipelineRule1 = new PipelineRule()
Expand Down Expand Up @@ -55,6 +56,7 @@ public void shouldReadMinimalConfig() {

// Default rules
assertThat(rules.getPipelineRules().size(), is(1));
assertThat(rules.getDisplayConsoleLogLinks(), is(true));
assertThat(rules.getDisplayMaterialChanges(), is(true));

PipelineRule pipelineRule = new PipelineRule()
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/configs/test-config-1.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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-log-links = false

# If you don't want to see the revision changes in the notification (for size or confidentiality concerns)
# defaults to true
displayMaterialChanges = false
Expand Down

0 comments on commit 973ede0

Please sign in to comment.