Skip to content

Commit

Permalink
fixed slackapi#84 for env variables in payload json file
Browse files Browse the repository at this point in the history
  • Loading branch information
razor54 committed Oct 21, 2022
1 parent 4466b60 commit b0da833
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/slack-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ module.exports = async function slackSend(core) {
try {
payload = await fs.readFile(path.resolve(payloadFilePath), 'utf-8');
// parse github context variables
const context = { github: github.context };
const payloadString = payload.replace('$', '');
const context = { github: github.context, env: process.env };
const payloadString = payload.replaceAll('$', '');
payload = markup.up(payloadString, context);
} catch (error) {
// passed in payload file path was invalid
Expand Down Expand Up @@ -129,7 +129,6 @@ module.exports = async function slackSend(core) {
} catch (err) {
console.log('axios post failed, double check the payload being sent includes the keys Slack expects');
console.log(payload);
// console.log(err);

if (err.response) {
core.setFailed(err.response.data);
Expand Down
3 changes: 2 additions & 1 deletion test/resources/valid-payload.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"oliver": "benji",
"bonny": "clyde",
"actor":"${{github.actor}}"
"actor":"${{github.actor}}",
"env_name": "${{env.ENV_NAME}}"
}
2 changes: 2 additions & 0 deletions test/slack-send-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('slack-send', () => {
describe('using a bot token', () => {
beforeEach(() => {
process.env.SLACK_BOT_TOKEN = 'xoxb-xxxxx';
process.env.ENV_NAME = 'test';
delete process.env.SLACK_WEBHOOK_URL;
});
describe('happy path', () => {
Expand Down Expand Up @@ -104,6 +105,7 @@ describe('slack-send', () => {
assert.equal(chatArgs.bonny, 'clyde', 'Correct message provided to postMessage');
assert.equal(chatArgs.oliver, 'benji', 'Correct message provided to postMessage');
assert.equal(chatArgs.actor, 'user123', 'Correct message provided to postMessage');
assert.equal(chatArgs.env_name, 'test', 'Correct message provided to postMessage');
});

it('should send the same message to multiple channels', async () => {
Expand Down

0 comments on commit b0da833

Please sign in to comment.