Skip to content

Instantly share code, notes, and snippets.

@jake
Last active June 1, 2016 02:37
Show Gist options
  • Save jake/7af9734c26e4a5bc199a20402ef25799 to your computer and use it in GitHub Desktop.
Save jake/7af9734c26e4a5bc199a20402ef25799 to your computer and use it in GitHub Desktop.
unity-cloud-build-share-url-to-slack hook.io source
module['exports'] = function echoHttp (hook) {
var request = require('request');
var Slack = require('slack-node');
var request_options = {
url: 'https://build-api.cloud.unity3d.com/api/v1',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + hook.env.UNITY_CLOUD_API_KEY
}
};
request_options.url += "/orgs/" + hook.params.orgid;
request_options.url += "/projects/" + hook.params.projectid;
request_options.url += "/buildtargets/" + hook.params.buildtargetid;
request_options.url += "/builds/" + hook.params.buildNumber;
request_options.url += "/share";
request.post(request_options, function(err, res, body){
if (err) {
return hook.res.end(err.messsage);
}
body = JSON.parse(body);
slack = new Slack();
slack.setWebhook(hook.env.SLACK_WEBHOOK_URL);
var message = {
username: "Unity Cloud Build",
icon_emoji: "https://unity3d.com/profiles/unity3d/themes/unity/images/assets/favicons/apple-touch-icon-152x152.png",
text: "Share URL: https://build.cloud.unity3d.com/share/" + body.shareid + "/"
};
slack.webhook(message, function(err, response) {
if (err) {
return hook.res.end(err);
}
hook.res.end(response);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment