From 6b2043fa475263ce0b0d2b518dd2b2e811382510 Mon Sep 17 00:00:00 2001 From: 839 <8398a7@gmail.com> Date: Fri, 7 Aug 2020 22:06:48 +0900 Subject: [PATCH] [#3] [command] npm run release --- dist/index.js | 85 ++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2e4d6afd..1b0fbf50 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3464,13 +3464,9 @@ function run() { }, process.env.GITHUB_TOKEN, process.env.SLACK_WEBHOOK_URL); switch (status) { case client_1.Success: - yield client.send(yield client.success(text)); - break; case client_1.Failure: - yield client.send(yield client.fail(text)); - break; case client_1.Cancelled: - yield client.send(yield client.cancel(text)); + yield client.send(yield client.prepare(text)); break; case client_1.Custom: yield client.send(yield client.custom(custom_payload)); @@ -4938,7 +4934,7 @@ module.exports = require("assert"); /***/ 361: /***/ (function(module) { -module.exports = {"name":"axios","version":"0.19.2","description":"Promise based HTTP client for the browser and node.js","main":"index.js","scripts":{"test":"grunt test && bundlesize","start":"node ./sandbox/server.js","build":"NODE_ENV=production grunt build","preversion":"npm test","version":"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json","postversion":"git push && git push --tags","examples":"node ./examples/server.js","coveralls":"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","fix":"eslint --fix lib/**/*.js"},"repository":{"type":"git","url":"https://github.com/axios/axios.git"},"keywords":["xhr","http","ajax","promise","node"],"author":"Matt Zabriskie","license":"MIT","bugs":{"url":"https://github.com/axios/axios/issues"},"homepage":"https://github.com/axios/axios","devDependencies":{"bundlesize":"^0.17.0","coveralls":"^3.0.0","es6-promise":"^4.2.4","grunt":"^1.0.2","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^20.1.0","grunt-karma":"^2.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^1.0.18","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1","karma":"^1.3.0","karma-chrome-launcher":"^2.2.0","karma-coverage":"^1.1.1","karma-firefox-launcher":"^1.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-opera-launcher":"^1.0.0","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^1.2.0","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^1.7.0","load-grunt-tasks":"^3.5.2","minimist":"^1.2.0","mocha":"^5.2.0","sinon":"^4.5.0","typescript":"^2.8.1","url-search-params":"^0.10.0","webpack":"^1.13.1","webpack-dev-server":"^1.14.1"},"browser":{"./lib/adapters/http.js":"./lib/adapters/xhr.js"},"typings":"./index.d.ts","dependencies":{"follow-redirects":"1.5.10"},"bundlesize":[{"path":"./dist/axios.min.js","threshold":"5kB"}],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.19.2.tgz","_integrity":"sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==","_from":"axios@0.19.2"}; +module.exports = {"_args":[["axios@0.19.2","/Users/husq/ghq/github.com/8398a7/action-slack"]],"_from":"axios@0.19.2","_id":"axios@0.19.2","_inBundle":false,"_integrity":"sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"axios@0.19.2","name":"axios","escapedName":"axios","rawSpec":"0.19.2","saveSpec":null,"fetchSpec":"0.19.2"},"_requiredBy":["/@slack/webhook"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.19.2.tgz","_spec":"0.19.2","_where":"/Users/husq/ghq/github.com/8398a7/action-slack","author":{"name":"Matt Zabriskie"},"browser":{"./lib/adapters/http.js":"./lib/adapters/xhr.js"},"bugs":{"url":"https://github.com/axios/axios/issues"},"bundlesize":[{"path":"./dist/axios.min.js","threshold":"5kB"}],"dependencies":{"follow-redirects":"1.5.10"},"description":"Promise based HTTP client for the browser and node.js","devDependencies":{"bundlesize":"^0.17.0","coveralls":"^3.0.0","es6-promise":"^4.2.4","grunt":"^1.0.2","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^20.1.0","grunt-karma":"^2.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^1.0.18","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1","karma":"^1.3.0","karma-chrome-launcher":"^2.2.0","karma-coverage":"^1.1.1","karma-firefox-launcher":"^1.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-opera-launcher":"^1.0.0","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^1.2.0","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^1.7.0","load-grunt-tasks":"^3.5.2","minimist":"^1.2.0","mocha":"^5.2.0","sinon":"^4.5.0","typescript":"^2.8.1","url-search-params":"^0.10.0","webpack":"^1.13.1","webpack-dev-server":"^1.14.1"},"homepage":"https://github.com/axios/axios","keywords":["xhr","http","ajax","promise","node"],"license":"MIT","main":"index.js","name":"axios","repository":{"type":"git","url":"git+https://github.com/axios/axios.git"},"scripts":{"build":"NODE_ENV=production grunt build","coveralls":"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","examples":"node ./examples/server.js","fix":"eslint --fix lib/**/*.js","postversion":"git push && git push --tags","preversion":"npm test","start":"node ./sandbox/server.js","test":"grunt test && bundlesize","version":"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json"},"typings":"./index.d.ts","version":"0.19.2"}; /***/ }), @@ -10004,7 +10000,7 @@ module.exports = (promise, onFinally) => { /***/ 698: /***/ (function(module) { -module.exports = {"name":"@slack/webhook","version":"5.0.3","description":"Official library for using the Slack Platform's Incoming Webhooks","author":"Slack Technologies, Inc.","license":"MIT","keywords":["slack","request","client","http","api","proxy"],"main":"dist/index.js","types":"./dist/index.d.ts","files":["dist/**/*"],"engines":{"node":">= 8.9.0","npm":">= 5.5.1"},"repository":"slackapi/node-slack-sdk","homepage":"https://slack.dev/node-slack-sdk/webhook","publishConfig":{"access":"public"},"bugs":{"url":"https://github.com/slackapi/node-slack-sdk/issues"},"scripts":{"prepare":"npm run build","build":"npm run build:clean && tsc","build:clean":"shx rm -rf ./dist ./coverage ./.nyc_output","lint":"tslint --project .","test":"npm run build && nyc mocha --config .mocharc.json src/*.spec.js","coverage":"codecov -F webhook --root=$PWD"},"dependencies":{"@slack/types":"^1.2.1","@types/node":">=8.9.0","axios":"^0.19.0"},"devDependencies":{"@types/chai":"^4.1.7","@types/mocha":"^5.2.6","chai":"^4.2.0","codecov":"^3.2.0","mocha":"^6.0.2","nock":"^10.0.6","nyc":"^14.1.1","shx":"^0.3.2","sinon":"^7.2.7","source-map-support":"^0.5.10","ts-node":"^8.0.3","tslint":"^5.13.1","tslint-config-airbnb":"^5.11.1","typescript":"^3.3.3333"},"_resolved":"https://registry.npmjs.org/@slack/webhook/-/webhook-5.0.3.tgz","_integrity":"sha512-51vnejJ2zABNumPVukOLyerpHQT39/Lt0TYFtOEz/N2X77bPofOgfPj2atB3etaM07mxWHLT9IRJ4Zuqx38DkQ==","_from":"@slack/webhook@5.0.3"}; +module.exports = {"_args":[["@slack/webhook@5.0.3","/Users/husq/ghq/github.com/8398a7/action-slack"]],"_from":"@slack/webhook@5.0.3","_id":"@slack/webhook@5.0.3","_inBundle":false,"_integrity":"sha512-51vnejJ2zABNumPVukOLyerpHQT39/Lt0TYFtOEz/N2X77bPofOgfPj2atB3etaM07mxWHLT9IRJ4Zuqx38DkQ==","_location":"/@slack/webhook","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"@slack/webhook@5.0.3","name":"@slack/webhook","escapedName":"@slack%2fwebhook","scope":"@slack","rawSpec":"5.0.3","saveSpec":null,"fetchSpec":"5.0.3"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/@slack/webhook/-/webhook-5.0.3.tgz","_spec":"5.0.3","_where":"/Users/husq/ghq/github.com/8398a7/action-slack","author":{"name":"Slack Technologies, Inc."},"bugs":{"url":"https://github.com/slackapi/node-slack-sdk/issues"},"dependencies":{"@slack/types":"^1.2.1","@types/node":">=8.9.0","axios":"^0.19.0"},"description":"Official library for using the Slack Platform's Incoming Webhooks","devDependencies":{"@types/chai":"^4.1.7","@types/mocha":"^5.2.6","chai":"^4.2.0","codecov":"^3.2.0","mocha":"^6.0.2","nock":"^10.0.6","nyc":"^14.1.1","shx":"^0.3.2","sinon":"^7.2.7","source-map-support":"^0.5.10","ts-node":"^8.0.3","tslint":"^5.13.1","tslint-config-airbnb":"^5.11.1","typescript":"^3.3.3333"},"engines":{"node":">= 8.9.0","npm":">= 5.5.1"},"files":["dist/**/*"],"homepage":"https://slack.dev/node-slack-sdk/webhook","keywords":["slack","request","client","http","api","proxy"],"license":"MIT","main":"dist/index.js","name":"@slack/webhook","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/slackapi/node-slack-sdk.git"},"scripts":{"build":"npm run build:clean && tsc","build:clean":"shx rm -rf ./dist ./coverage ./.nyc_output","coverage":"codecov -F webhook --root=$PWD","lint":"tslint --project .","prepare":"npm run build","test":"npm run build && nyc mocha --config .mocharc.json src/*.spec.js"},"types":"./dist/index.d.ts","version":"5.0.3"}; /***/ }), @@ -10072,35 +10068,9 @@ class Client { if (process.env.MATRIX_CONTEXT == null || process.env.MATRIX_CONTEXT === 'null') return github_1.context.job; - const os = JSON.parse(process.env.MATRIX_CONTEXT).os; - return os !== '' ? `${github_1.context.job} (${os})` : github_1.context.job; - } - success(text) { - return __awaiter(this, void 0, void 0, function* () { - const template = yield this.payloadTemplate(); - template.attachments[0].color = 'good'; - template.text += this.mentionText(this.with.mention, exports.Success); - template.text += this.insertText(':white_check_mark: Succeeded GitHub Actions\n', text); - return template; - }); - } - fail(text) { - return __awaiter(this, void 0, void 0, function* () { - const template = yield this.payloadTemplate(); - template.attachments[0].color = 'danger'; - template.text += this.mentionText(this.with.mention, exports.Failure); - template.text += this.insertText(':no_entry: Failed GitHub Actions\n', text); - return template; - }); - } - cancel(text) { - return __awaiter(this, void 0, void 0, function* () { - const template = yield this.payloadTemplate(); - template.attachments[0].color = 'warning'; - template.text += this.mentionText(this.with.mention, exports.Cancelled); - template.text += this.insertText(':warning: Canceled GitHub Actions\n', text); - return template; - }); + const matrix = JSON.parse(process.env.MATRIX_CONTEXT); + const value = Object.values(matrix).join(', '); + return value !== '' ? `${github_1.context.job} (${value})` : github_1.context.job; } custom(payload) { return __awaiter(this, void 0, void 0, function* () { @@ -10111,6 +10081,14 @@ class Client { return template; }); } + prepare(text) { + return __awaiter(this, void 0, void 0, function* () { + const template = yield this.payloadTemplate(); + template.text = this.injectText(text); + template.attachments[0].color = this.injectColor(); + return template; + }); + } send(payload) { return __awaiter(this, void 0, void 0, function* () { core.debug(JSON.stringify(github_1.context, null, 2)); @@ -10118,6 +10096,35 @@ class Client { core.debug('send message'); }); } + injectColor() { + switch (this.with.status) { + case exports.Success: + return 'good'; + case exports.Cancelled: + return 'warning'; + case exports.Failure: + return 'danger'; + } + throw new Error(`invalid status: ${this.with.status}`); + } + injectText(value) { + let text = ''; + switch (this.with.status) { + case exports.Success: + text += this.mentionText(exports.Success); + text += this.insertText(':white_check_mark: Succeeded GitHub Actions\n', value); + return text; + case exports.Cancelled: + text += this.mentionText(exports.Cancelled); + text += this.insertText(':warning: Canceled GitHub Actions\n', value); + return text; + case exports.Failure: + text += this.mentionText(exports.Failure); + text += this.insertText(':no_entry: Failed GitHub Actions\n', value); + return text; + } + throw new Error(`invalid status: ${this.with.status}`); + } payloadTemplate() { return __awaiter(this, void 0, void 0, function* () { const text = ''; @@ -10144,9 +10151,9 @@ class Client { else return `<@${id}>`; } - mentionText(mention, status) { - if (!this.with.if_mention.includes(status) && - this.with.if_mention !== exports.Always) { + mentionText(status) { + const { mention, if_mention } = this.with; + if (!if_mention.includes(status) && if_mention !== exports.Always) { return ''; } const normalized = mention.replace(/ /g, '');