This repository has been archived by the owner on Aug 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from jrit/master
Slack channel build notifications
- Loading branch information
Showing
4 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,14 +29,13 @@ Configuration of this plugin relies heavily on 3 files: | |
```js | ||
module.exports = function ( grunt ) | ||
{ | ||
"use strict"; | ||
|
||
// for environment configuration | ||
var env = grunt.option( "env" ) || "local"; | ||
grunt.initConfig( { | ||
env: grunt.file.readJSON( "env.json" )[ env ], | ||
envName: env, | ||
version: grunt.option( "gitver" ) || Date.now() // for deployment cache-busting | ||
version: grunt.option( "gitver" ) || Date.now(), // for deployment cache-busting | ||
slackApiToken: grunt.option( "slacktoken" ) // if using slack notifications | ||
} ); | ||
|
||
var path = require( "path" ); | ||
|
@@ -92,7 +91,8 @@ Configuration of this plugin relies heavily on 3 files: | |
"aws.s3Bucket": "yourapp-dev", | ||
"aws.distributionId": "ABCDEFGHIJKLMN", | ||
"notification.emailTo": "[email protected]", | ||
"notification.emailFrom": "[email protected]" | ||
"notification.emailFrom": "[email protected]", | ||
"notification.slackChannel": "channelname" | ||
}, | ||
"staging": { | ||
"apiroot": "https://api-staging.yourapp.com", | ||
|
@@ -101,7 +101,8 @@ Configuration of this plugin relies heavily on 3 files: | |
"aws.s3Bucket": "yourapp-staging", | ||
"aws.distributionId": "OPQRSTUVWXYZAB", | ||
"notification.emailTo": [ "[email protected]", "[email protected]" ], | ||
"notification.emailFrom": "[email protected]" | ||
"notification.emailFrom": "[email protected]", | ||
"notification.slackChannel": "channelname" | ||
}, | ||
"prod": { | ||
"apiroot": "https://api.yourapp.com", | ||
|
@@ -110,7 +111,8 @@ Configuration of this plugin relies heavily on 3 files: | |
"aws.s3Bucket": "yourapp-prod", | ||
"aws.distributionId": "JKLMNOPQRSTUVW", | ||
"notification.emailTo": [ "[email protected]", "[email protected]" ], | ||
"notification.emailFrom": "[email protected]" | ||
"notification.emailFrom": "[email protected]", | ||
"notification.slackChannel": "channelname" | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use strict"; | ||
|
||
var Slack = require( "slack-node" ); | ||
|
||
module.exports = function ( grunt ) | ||
{ | ||
var envConfig = grunt.config( "env" ); | ||
var slackApiToken = grunt.config( "slackApiToken" ); | ||
var deployVersion = grunt.config( "version" ); | ||
var pkgVersion = grunt.file.readJSON( "package.json" ).version || ""; | ||
|
||
grunt.registerTask( "notification_slack", "Notify a Slack channel that a deployment is going out", function () | ||
{ | ||
var done = this.async(); | ||
|
||
var slackChannel = envConfig[ "notification.slackChannel" ]; | ||
var host = envConfig.host; | ||
|
||
if( !slackChannel || !slackApiToken || !host ) | ||
{ | ||
grunt.log.ok( "Slack Notification exiting without sending" ); | ||
done(); | ||
return; | ||
} | ||
|
||
var slacker = new Slack( slackApiToken ); | ||
|
||
slacker.api( "chat.postMessage", { | ||
text: "Build " + pkgVersion + " @" + deployVersion + " for " + host | ||
+ " should be available in about 10 minutes.", | ||
channel: slackChannel, | ||
username: "Release Bot" | ||
}, | ||
function ( err, res ) | ||
{ | ||
if( err ) | ||
{ | ||
grunt.fail.warn( err, err.stack ); | ||
} | ||
else | ||
{ | ||
grunt.log.ok( "Slack Notification sent" ); | ||
grunt.log.write( JSON.stringify( res ) ); | ||
} | ||
done(); | ||
} ); | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters