Skip to content

Commit

Permalink
add options
Browse files Browse the repository at this point in the history
  • Loading branch information
abeyuya committed Mar 26, 2020
1 parent b0b5151 commit 086dd48
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
21 changes: 17 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,29 @@ var buildSlackPostMessage = function (slackIdsForMention, issueTitle, commentLin
].join("\n");
};
var postToSlack = function (webhookUrl, message) { return __awaiter(void 0, void 0, void 0, function () {
var slackOption;
var botName, slackOption, iconUrl;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
botName = (function () {
var n = core.getInput("bot-name", { required: false });
if (n && n !== "") {
return n;
}
return "Github Mention To Slack";
})();
slackOption = {
text: message,
link_names: 1,
username: "Github Mention To Slack",
icon_emoji: ":bell:"
link_names: 0,
username: botName
};
iconUrl = core.getInput("icon-url", { required: false });
if (iconUrl && iconUrl !== "") {
slackOption.icon_url = iconUrl;
}
else {
slackOption.icon_emoji = ":bell:";
}
return [4 /*yield*/, axios_1["default"].post(webhookUrl, JSON.stringify(slackOption), {
headers: { "Content-Type": "application/json" }
})];
Expand Down
30 changes: 26 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,36 @@ const buildSlackPostMessage = (
].join("\n");
};

type SlackOption = {
text: string;
link_names: 0 | 1;
username: string;
icon_url?: string;
icon_emoji?: string;
};

const postToSlack = async (webhookUrl: string, message: string) => {
const slackOption = {
const botName = (() => {
const n = core.getInput("bot-name", { required: false });
if (n && n !== "") {
return n;
}
return "Github Mention To Slack";
})();

const slackOption: SlackOption = {
text: message,
link_names: 1,
username: "Github Mention To Slack",
icon_emoji: ":bell:"
link_names: 0,
username: botName
};

const iconUrl = core.getInput("icon-url", { required: false });
if (iconUrl && iconUrl !== "") {
slackOption.icon_url = iconUrl;
} else {
slackOption.icon_emoji = ":bell:";
}

await axios.post(webhookUrl, JSON.stringify(slackOption), {
headers: { "Content-Type": "application/json" }
});
Expand Down

0 comments on commit 086dd48

Please sign in to comment.