Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for iconURL and iconEmoji config props #12

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ The channel in slack that the notification should be displayed in in Slack.

The username that will send the message in Slack.

###iconURL

URL to an image to use as the message's icon.

###iconEmoji

Slack emoji code to use as the message's icon (like `:heart_eyes_cat:` or `:saxophone:`).

## Customization

`ember-cli-deploy-slack` will send default messages on the `didDeploy`- and
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,16 @@ module.exports = {

var channel = this.readConfig('channel');
var username = this.readConfig('username');
var iconURL = this.readConfig('iconURL');
var iconEmoji = this.readConfig('iconEmoji');

return this.readConfig('slackNotifier') || new SlackNotifier({
enabled: enabled,
webhookURL: webhookURL,
channel: channel,
username: username
username: username,
iconURL: iconURL,
iconEmoji: iconEmoji
});
}
});
Expand Down
19 changes: 15 additions & 4 deletions lib/slack-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ module.exports = CoreObject.extend({
init: function(data) {
this._super(data);

this.slack = new Slack(this.webhookURL, {
channel: this.channel,
username: this.username
});
this.slack = new Slack(this.webhookURL, this._getSlackOptions());

this.notify = function(message) {
return new Promise(function(resolve, reject) {
Expand All @@ -24,5 +21,19 @@ module.exports = CoreObject.extend({
}
}.bind(this));
}
},

_getSlackOptions: function () {
var options = {
channel: this.channel,
username: this.username
};
if (this.iconURL) {
options.icon_url = this.iconURL;
}
if (this.iconEmoji) {
options.icon_emoji = this.iconEmoji;
}
return options;
}
});
36 changes: 36 additions & 0 deletions node-tests/unit/slack-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ describe('SlackNotifier', function() {
expect(slack.username).to.eql(USER_NAME);
});

describe('#_getSlackOptions', function() {
it("snake_cases and adds `iconURL` and/or `iconEmoji` options if they are set", function() {
var iconEmojiOnly = new SlackNotifier({
enabled: true,
webhookURL: WEBHOOK_URL,
channel: CHANNEL,
username: USER_NAME,
iconEmoji: ':dromedary_camel:'
});
var bothOptions = new SlackNotifier({
enabled: true,
webhookURL: WEBHOOK_URL,
channel: CHANNEL,
username: USER_NAME,
iconEmoji: ':dromedary_camel:',
iconURL: 'http://placehold.it/128x128'
});

expect(slack._getSlackOptions()).to.eql({
channel: CHANNEL,
username: USER_NAME
});
expect(iconEmojiOnly._getSlackOptions()).to.eql({
channel: CHANNEL,
username: USER_NAME,
icon_emoji: ':dromedary_camel:'
});
expect(bothOptions._getSlackOptions()).to.eql({
channel: CHANNEL,
username: USER_NAME,
icon_emoji: ':dromedary_camel:',
icon_url: 'http://placehold.it/128x128'
});
});
});

describe('enabled', function() {
describe('#notify', function() {
it('is callable', function() {
Expand Down