Skip to content

Instantly share code, notes, and snippets.

@kechol
Last active May 22, 2019 13:58
Show Gist options
  • Save kechol/d05ea6f186bb75671dbe3860db3c13cf to your computer and use it in GitHub Desktop.
Save kechol/d05ea6f186bb75671dbe3860db3c13cf to your computer and use it in GitHub Desktop.
Cloud function to notify labeled issue.
"use strict";
const request = require("request");
const SLACK_WEBHOOK_URL = "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXXXXXXXX";
const LABEL_NAMES = ["bug"];
exports.notifyLabelIssue = (req, res) => {
console.log(req.body);
if (req.body.action === "labeled" && req.body.issue.labels.some((l) => LABEL_NAMES.includes(l.name))) {
request.post({
url: SLACK_WEBHOOK_URL,
form: "payload=" + JSON.stringify({
text: req.body.issue.html_url,
username: "notify-label-issue",
icon_emoji: ":memo:",
unfurl_links: true,
}),
json: true,
});
}
res.send(200);
};
{
"name": "notify-label-issue",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">=8"
},
"dependencies": {
"request": "^2.88.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment