fixed #51 for env variables in payload json file
This commit is contained in:
Generated
+15
-1
@@ -13,7 +13,8 @@
|
||||
"@actions/github": "^5.0.0",
|
||||
"@slack/web-api": "^6.7.0",
|
||||
"axios": "^0.25.0",
|
||||
"flat": "^5.0.2"
|
||||
"flat": "^5.0.2",
|
||||
"markup-js": "^1.5.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "^0.33.3",
|
||||
@@ -3687,6 +3688,14 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/markup-js": {
|
||||
"version": "1.5.21",
|
||||
"resolved": "https://registry.npmjs.org/markup-js/-/markup-js-1.5.21.tgz",
|
||||
"integrity": "sha1-OJEocDpWWWRXTQ41fhQq3TvkbXk=",
|
||||
"bin": {
|
||||
"markup-js": "src/markup.js"
|
||||
}
|
||||
},
|
||||
"node_modules/md5.js": {
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
|
||||
@@ -8421,6 +8430,11 @@
|
||||
"semver": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"markup-js": {
|
||||
"version": "1.5.21",
|
||||
"resolved": "https://registry.npmjs.org/markup-js/-/markup-js-1.5.21.tgz",
|
||||
"integrity": "sha1-OJEocDpWWWRXTQ41fhQq3TvkbXk="
|
||||
},
|
||||
"md5.js": {
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
|
||||
|
||||
+2
-1
@@ -34,7 +34,8 @@
|
||||
"@actions/github": "^5.0.0",
|
||||
"@slack/web-api": "^6.7.0",
|
||||
"axios": "^0.25.0",
|
||||
"flat": "^5.0.2"
|
||||
"flat": "^5.0.2",
|
||||
"markup-js": "^1.5.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "^0.33.3",
|
||||
|
||||
@@ -4,6 +4,7 @@ const flatten = require('flat');
|
||||
const axios = require('axios');
|
||||
const { promises: fs } = require('fs');
|
||||
const path = require('path');
|
||||
const markup = require('markup-js');
|
||||
|
||||
const SLACK_WEBHOOK_TYPES = {
|
||||
WORKFLOW_TRIGGER: 'WORKFLOW_TRIGGER',
|
||||
@@ -33,6 +34,10 @@ module.exports = async function slackSend(core) {
|
||||
if (payloadFilePath && !payload) {
|
||||
try {
|
||||
payload = await fs.readFile(path.resolve(payloadFilePath), 'utf-8');
|
||||
// parse github context variables
|
||||
const context = { github: github.context };
|
||||
const payloadString = payload.replace('$', '');
|
||||
payload = markup.up(payloadString, context);
|
||||
} catch (error) {
|
||||
// passed in payload file path was invalid
|
||||
console.error(error);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"oliver": "benji",
|
||||
"bonny": "clyde"
|
||||
"bonny": "clyde",
|
||||
"actor":"${{github.actor}}"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const { assert } = require('chai');
|
||||
const sinon = require('sinon');
|
||||
const core = require('@actions/core');
|
||||
const github = require('@actions/github');
|
||||
const rewiremock = require('rewiremock/node');
|
||||
|
||||
const ChatStub = {
|
||||
@@ -30,6 +31,7 @@ const ORIG_WEBHOOK_VAR = process.env.SLACK_WEBHOOK_URL;
|
||||
|
||||
describe('slack-send', () => {
|
||||
const fakeCore = sinon.stub(core);
|
||||
const fakeGithub = sinon.stub(github);
|
||||
beforeEach(() => {
|
||||
sinon.reset();
|
||||
});
|
||||
@@ -66,6 +68,7 @@ describe('slack-send', () => {
|
||||
// Prepare
|
||||
fakeCore.getInput.withArgs('channel-id').returns('C123456');
|
||||
fakeCore.getInput.withArgs('payload-file-path').returns('./test/resources/valid-payload.json');
|
||||
fakeGithub.context.actor = 'user123';
|
||||
|
||||
// Run
|
||||
await slackSend(fakeCore);
|
||||
@@ -78,6 +81,7 @@ describe('slack-send', () => {
|
||||
assert.equal(chatArgs.text, '', 'Correct message provided to postMessage');
|
||||
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');
|
||||
});
|
||||
});
|
||||
describe('sad path', () => {
|
||||
|
||||
Reference in New Issue
Block a user