Skip to content

Commit

Permalink
Merge pull request #64 from ashwanthkumar/truncate-changes-option
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
ashwanthkumar authored Dec 2, 2016
2 parents 13858df + d677be3 commit 2708d81
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ gocd.slack {
- `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.
- `truncate-changes` - If true, displays only the latest 5 changes for all the materials. (Default: true)
- `proxy` - Specify proxy related settings for the plugin.
- `proxy.hostname` - Proxy Host
- `proxy.port` - Proxy Port
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ gocd.slack {
- `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.
- `truncate-changes` - If true, displays only the latest 5 changes for all the materials. (Default: true)
- `proxy` - Specify proxy related settings for the plugin.
- `proxy.hostname` - Proxy Host
- `proxy.port` - Proxy Port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static in.ashwanthkumar.utils.lang.StringUtils.startsWith;

public class SlackPipelineListener extends PipelineListener {
public static final int MAX_CHANGES_PER_MATERIAL_IN_SLACK = 5;
public static final int DEFAULT_MAX_CHANGES_PER_MATERIAL_IN_SLACK = 5;
private Logger LOG = Logger.getLoggerFor(SlackPipelineListener.class);

private final Slack slack;
Expand Down Expand Up @@ -113,8 +113,8 @@ private SlackAttachment slackAttachment(PipelineRule rule, GoNotificationMessage
StringBuilder sb = new StringBuilder();
for (MaterialRevision change : changes) {
boolean isTruncated = false;
if (change.modifications.size() > MAX_CHANGES_PER_MATERIAL_IN_SLACK) {
change.modifications = Lists.take(change.modifications, MAX_CHANGES_PER_MATERIAL_IN_SLACK);
if (rules.isTruncateChanges() && change.modifications.size() > DEFAULT_MAX_CHANGES_PER_MATERIAL_IN_SLACK) {
change.modifications = Lists.take(change.modifications, DEFAULT_MAX_CHANGES_PER_MATERIAL_IN_SLACK);
isTruncated = true;
}
for (Modification mod : change.modifications) {
Expand All @@ -136,7 +136,7 @@ private SlackAttachment slackAttachment(PipelineRule rule, GoNotificationMessage
}
sb.append("\n");
}
String fieldNamePrefix = (isTruncated) ? String.format("Latest %d", MAX_CHANGES_PER_MATERIAL_IN_SLACK) : "All";
String fieldNamePrefix = (isTruncated) ? String.format("Latest %d", DEFAULT_MAX_CHANGES_PER_MATERIAL_IN_SLACK) : "All";
String fieldName = String.format("%s changes for %s", fieldNamePrefix, change.material.description);
buildAttachment.addField(new SlackAttachment.Field(fieldName, sb.toString(), false));
}
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 @@ -32,6 +32,7 @@ public class Rules {
private boolean displayConsoleLogLinks;
private boolean displayMaterialChanges;
private boolean processAllRules;
private boolean truncateChanges;

private Proxy proxy;

Expand Down Expand Up @@ -159,6 +160,15 @@ public Rules setProcessAllRules(boolean processAllRules) {
return this;
}

public boolean isTruncateChanges() {
return truncateChanges;
}

public Rules setTruncateChanges(boolean truncateChanges) {
this.truncateChanges = truncateChanges;
return this;
}

public Proxy getProxy() {
return proxy;
}
Expand Down Expand Up @@ -240,6 +250,11 @@ public static Rules fromConfig(Config config) {
processAllRules = config.getBoolean("process-all-rules");
}

boolean truncateChanges = true;
if(config.hasPath("truncate-changes")) {
truncateChanges = config.getBoolean("truncate-changes");
}

Proxy proxy = null;
if (config.hasPath("proxy")) {
Config proxyConfig = config.getConfig("proxy");
Expand Down Expand Up @@ -274,6 +289,7 @@ public PipelineRule apply(Config input) {
.setDisplayConsoleLogLinks(displayConsoleLogLinks)
.setDisplayMaterialChanges(displayMaterialChanges)
.setProcessAllRules(processAllRules)
.setTruncateChanges(truncateChanges)
.setProxy(proxy);
try {
rules.pipelineListener = Class.forName(config.getString("listener")).asSubclass(PipelineListener.class).getConstructor(Rules.class).newInstance(rules);
Expand Down

0 comments on commit 2708d81

Please sign in to comment.