Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps-dev): bump nyc from 17.0.0 to 17.1.0 #52

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ inputs:
required: false
update-ts: # The timestamp of a previous message posted to update it instead of posting a new message
description: 'The timestamp of a previous message posted. It will update the existing message instead of posting a new message'
payload-context: # path to JSON payload to send to Slack via webhook
description: 'Payload context to markup the variables'
required: false
outputs:
time: # id of output
Expand Down
39 changes: 33 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"eslint-plugin-jsdoc": "^50.2.2",
"eslint-plugin-node": "^11.1.0",
"mocha": "^10.7.3",
"nyc": "^17.0.0",
"nyc": "^17.1.0",
"rewiremock": "^3.14.5",
"sinon": "^18.0.0"
}
Expand Down
41 changes: 33 additions & 8 deletions src/slack-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = async function slackSend(core) {
}

let payload = core.getInput('payload');

const payloadFilePath = core.getInput('payload-file-path');

/** Option to replace templated context variables in the payload file JSON */
Expand All @@ -42,9 +41,26 @@ module.exports = async function slackSend(core) {
try {
payload = await fs.readFile(path.resolve(payloadFilePath), 'utf-8');
if (payloadFilePathParsed) {
const context = { github: github.context, env: process.env };
const payloadString = payload.replaceAll('${{', '{{');
payload = markup.up(payloadString, context);
let payloadContext = JSON.parse(core.getInput('payload-context').replace(/(\r\n|\n|\r)/gm, ""));
if (typeof payloadContext === 'string') {
payloadContext = JSON.parse(payloadContext);
}
const statsuColors = {
success: '#2eb886',
failure: '#dc3545',
cancelled: '#ffc107'
};
const statusuMessages = {
success: payloadContext.success_text || 'Succeed',
failure: payloadContext.failure_text || 'Failed',
cancelled: payloadContext.cancelled_text || 'Cancelled',
};
payloadContext.color = statsuColors[payloadContext.job_status];
payloadContext.message_text = statusuMessages[payloadContext.job_status];
payloadContext.posted_time = `<!date^${Math.round(+new Date() / 1000)}^posted at {date_long_pretty} {time}|posted at Mon, 14 Mar 2022 02:42 GMT>`;
payload = markup.up(payload.replace(/\$/g, ''), {
context: payloadContext,
});
}
} catch (error) {
// passed in payload file path was invalid
Expand Down Expand Up @@ -79,11 +95,20 @@ module.exports = async function slackSend(core) {
const ts = core.getInput('update-ts');
await Promise.all(channelIds.split(',').map(async (channelId) => {
if (ts) {
// update message
webResponse = await web.chat.update({ ts, channel: channelId.trim(), text: message, ...(payload || {}) });
// update message
webResponse = await web.chat.update({
ts,
channel: channelId.trim(),
text: message,
...(payload || {}),
});
} else {
// post message
webResponse = await web.chat.postMessage({ channel: channelId.trim(), text: message, ...(payload || {}) });
// post message
webResponse = await web.chat.postMessage({
channel: channelId.trim(),
text: message,
...(payload || {}),
});
}
}));
} else {
Expand Down
Loading