Created
December 22, 2016 18:27
-
-
Save gbaeke/9e92b4a33e41793f1d6c454cfc496bd6 to your computer and use it in GitHub Desktop.
A Slash WebTask for Slack to run a build on Shippable
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
var request=require('request'); | |
module.exports = function (ctx, cb) { | |
var shippable_secret=ctx.secrets.shippable; // API token for shippable API | |
var project=ctx.body.text; // project name passed as parameter to Slash command | |
// do not want to look up the project id in code; create dictionary here | |
var projects={ | |
realtime: '<Shippable project id>' | |
}; | |
// check if user specifies a correct project | |
if(!projects[project]) { | |
cb(null, { | |
response_type: 'in_channel', | |
text: 'Sorry, specify a valid project!' | |
}); | |
} | |
// call shippable API to build project | |
var options = { | |
method: 'POST', | |
url: 'https://api.shippable.com/projects/' + projects[project] + '/newBuild', | |
headers: { | |
'Authorization': 'apiToken ' + shippable_secret | |
} | |
}; | |
// we do not specify a callback or do error checking; user should check if he gets a build report in Slack | |
request(options); | |
cb(null, { | |
response_type: 'in_channel', | |
text: 'Build request for ' + project + ' fired! Check Slack for status.' | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment