Skip to content

Instantly share code, notes, and snippets.

@gbaeke
Created December 22, 2016 18:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbaeke/9e92b4a33e41793f1d6c454cfc496bd6 to your computer and use it in GitHub Desktop.
Save gbaeke/9e92b4a33e41793f1d6c454cfc496bd6 to your computer and use it in GitHub Desktop.
A Slash WebTask for Slack to run a build on Shippable
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