Skip to content

Commit

Permalink
Update plugin config to allow specification of complete weboook url
Browse files Browse the repository at this point in the history
(fixes #3)
  • Loading branch information
gitblit committed Nov 10, 2015
1 parent ae327e0 commit 3660a76
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Gitblit Slack plugin

## 1.4.0-SNAPSHOT

- Update to Gitblit 1.7.0
- Add `slack.url` config setting
- Remove `slack.team`
- Remove `slack.token`

### 1.3.0

- Post events using user identity & gravatar, may be disabled
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Alternatively, you can download the zip from [here](http://plugins.gitblit.com)

### Setup

At a bare minimum you'll need two settings configured in `gitblit.properties`.
At a bare minimum you'll need one setting configured in `gitblit.properties`.

slack.url = https://hooks.slack.com/services/yada/yadayada

slack.team = yourTeam
slack.token = yourToken

If you have the `powertools` plugin installed, you may configure this over SSH:

ssh host gb config slack.team yourTeam
ssh host gb config slack.token yourToken
ssh host gb config slack.url https://hooks.slack.com/services/yada/yadayada


There a handful of additional optional settings:

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/gitblit/plugin/slack/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@

public class Plugin extends GitblitPlugin {

public static final String SETTING_TEAM = "slack.team";

public static final String SETTING_HOOK = "slack.hook";

public static final String SETTING_TOKEN = "slack.token";
public static final String SETTING_URL = "slack.url";

public static final String SETTING_POST_AS_USER = "slack.postAsUser";

Expand Down
19 changes: 4 additions & 15 deletions src/main/java/com/gitblit/plugin/slack/Slacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,11 @@ public boolean shallPost(RepositoryModel repository) {
}

public String getURL() throws IOException {
String team = runtimeManager.getSettings().getString(Plugin.SETTING_TEAM, null);
if (StringUtils.isEmpty(team)) {
throw new IOException(String.format("Could not send message to Slack because '%s' is not defined!", Plugin.SETTING_TEAM));
String url = runtimeManager.getSettings().getString(Plugin.SETTING_URL, null);
if (StringUtils.isEmpty(url)) {
throw new IOException(String.format("Could not send message to Slack because '%s' is not defined!", Plugin.SETTING_URL));
}

String token = runtimeManager.getSettings().getString(Plugin.SETTING_TOKEN, null);
if (StringUtils.isEmpty(token)) {
throw new IOException(String.format("Could not send message to Slack because '%s' is not defined!", Plugin.SETTING_TOKEN));
}

String hook = runtimeManager.getSettings().getString(Plugin.SETTING_HOOK, "incoming-webhook");
if (StringUtils.isEmpty(hook)) {
hook = "incoming-webhook";
}

return String.format("https://%s.slack.com/services/hooks/%s?token=%s", team.toLowerCase(), hook, token);
return url;
}

/**
Expand Down

0 comments on commit 3660a76

Please sign in to comment.