diff --git a/README.md b/README.md index 1c3f293..704157b 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,79 @@ # Ember-cli-deploy-slack -This README outlines the details of collaborating on this Ember addon. +An ember-cli-deploy-plugin for sending deployment messages to [Slack](https://slack.com/). -## Installation +## Usage -* `git clone` this repository -* `npm install` -* `bower install` +This plugin will only work with the upcoming 0.5.0-release of +[ember-cli-deploy](https://github.com/ember-cli/ember-cli-deploy). Right now +you have to use my [didFail branch](levelbossmike/ember-cli-deploy#didFail-hook-). -## Running +To setup ember-cli-deploy-slack you need to add a `slack`-entry into your +`deploy.js` configuration file: -* `ember server` -* Visit your app at http://localhost:4200. +```js +module.exports = function(environment) { + var environments = { + "development": { + // ... + "slack": { + "webhookURL": "https://hooks.slack.com/services/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", + "channel": "#notifications", + "username": "ember-cli-deploy" + }, + // ... + }, -## Running Tests + "staging": { + // ... + }, -* `ember test` -* `ember test --server` + "production": { + // ... + } + }; -## Building + return environments[environment]; +}; +``` -* `ember build` +## Customization -For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/). +`ember-cli-deploy-slack` will send default messages on the `didDeploy`- and +`didFail`-hooks on the pipeline. Because every team is different and people +tend to customize their automatic slack notifications messages can be +customized. + +To customize a message you simply add a function to your slack configuration +options that is named the same as the hook notification you want to customize: + +```js +module.exports = function(environment) { + var environments = { + "development": { + // ... + "slack": { + "webhookURL": "https://hooks.slack.com/services/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", + "channel": "#notifications", + "username": "ember-cli-deploy", + "didDeploy": function(context, slack) { + return slack.notify({ + text: 'w00t I can haz custumizations!' + }); + } + }, + // ... + }, +``` + + +Notification hooks will be passed the deployment context and the slackNotifier +utility class. The SlackNotifier uses [node-slackr](https://github.com/chenka/node-slackr) under the hood so you can use its `notify`-function accordingly. This enables you to customize your messages in any way possible. You can even add custom properties to the deployment context if that's what you need to do. + +Please see the [Slack API documentation for message formatting](https://api.slack.com/docs/formatting) +to see how you can customize your messages. + +### Available hooks + +`willDeploy`, `willBuild`, `build`, `didBuild`, `willActivate`, `activate`, +`didActivate`, `didDeploy`, `didFail` diff --git a/index.js b/index.js index d06a82f..0d7518e 100644 --- a/index.js +++ b/index.js @@ -12,10 +12,12 @@ var yellow = chalk.yellow; function applyDefaultConfigIfNecessary(config, prop, defaultConfig, ui){ if (!config[prop]) { - var value = defaultConfig[prop]; + var value = defaultConfig[prop] || function() { return; }; config[prop] = value; - ui.write(blue('| ')); - ui.writeLine(yellow('- Missing config: `' + prop + '`, using default: `' + value + '`')); + if (defaultConfig[prop]) { + ui.write(blue('| ')); + ui.writeLine(yellow('- Missing config: `' + prop + '`, using default: `' + value + '`')); + } } } @@ -63,6 +65,42 @@ module.exports = { return executeSlackNotificationHook.bind(this)(context, 'willDeploy'); }, + willBuild: function(context) { + return executeSlackNotificationHook.bind(this)(context, 'willBuild'); + }, + + build: function(context) { + return executeSlackNotificationHook.bind(this)(context, 'build'); + }, + + didBuild: function(context) { + return executeSlackNotificationHook.bind(this)(context, 'didBuild'); + }, + + willUpload: function(context) { + return executeSlackNotificationHook.bind(this)(context, 'willUpload'); + }, + + upload: function(context) { + return executeSlackNotificationHook.bind(this)(context, 'upload'); + }, + + didUpload: function(context) { + return executeSlackNotificationHook.bind(this)(context, 'didUpload'); + }, + + willActivate: function(context) { + return executeSlackNotificationHook.bind(this)(context, 'willActivate'); + }, + + activate: function(context) { + return executeSlackNotificationHook.bind(this)(context, 'activate'); + }, + + didActivate: function(context) { + return executeSlackNotificationHook.bind(this)(context, 'didActivate'); + }, + didDeploy: function(context) { return executeSlackNotificationHook.bind(this)(context, 'didDeploy'); }, diff --git a/package.json b/package.json index 5e55909..287569c 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "ember-cli-deploy-slack", - "version": "0.0.0", - "description": "The default blueprint for ember-cli addons.", + "version": "0.0.1", + "description": "An ember-cli-deploy-plugin for sending messages to Slack", "directories": { "doc": "doc", "test": "tests" }, + "repository": "https://github.com/LevelbossMike/ember-cli-deploy-slack", "scripts": { "start": "ember server", "build": "ember build",