Compare commits

..

4 Commits

Author SHA1 Message Date
zcong1993 2a68a4d06e fix(core): bump deps and pack action to fix #4 2020-07-06 11:31:21 +08:00
featherlight 5cf291c851 Merge pull request #4 from kuitos/fix/unnessary-json-parse
fix: parse body may cause JSON parse error while send markdown message
2020-07-06 11:28:55 +08:00
Kuitos dbf39fd4a7 fix: parse body not make sense and it would cause JSON parse error 2020-07-06 00:58:55 +08:00
zcong1993 6795ef8f80 feat: support ignore error and update readme 2020-06-20 23:59:16 +08:00
6 changed files with 139 additions and 100 deletions
+12 -1
View File
@@ -2,6 +2,17 @@
Send dingding simple notify message.
## Usage
| option | required | description |
| ----------- | -------- | ------------------------------------------------------------------------------------------------------------------- |
| dingToken | true | DingDing bot access_token |
| body | true | any kind of message body [dingding](https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq) support into `body` field |
| secret | false | if secret set, action will call API with sign |
| ignoreError | false | if set true, will not fail action when API call failed |
## Examples
```yaml
- name: Send dingding notify
uses: zcong1993/actions-ding@master
@@ -19,7 +30,7 @@ Send dingding simple notify message.
}
```
## sign
### with sign
```yaml
- name: Send dingding notify
+3
View File
@@ -14,6 +14,9 @@ inputs:
secret:
description: 'If use sign secret'
required: false
ignoreError:
description: 'If set true, will not fail action when API call failed'
required: false
runs:
using: 'node12'
+103 -88
View File
@@ -385,7 +385,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(116));
const ding_bot_1 = __webpack_require__(808);
const ding_bot_1 = __webpack_require__(574);
const endpoint = 'https://oapi.dingtalk.com/robot/send';
function run() {
var _a, _b;
@@ -394,8 +394,8 @@ function run() {
const token = core.getInput('dingToken');
const body = core.getInput('body');
const secretStr = core.getInput('secret');
const ignoreError = core.getInput('ignoreError') === 'true';
const secret = secretStr === '' ? undefined : secretStr;
const data = JSON.parse(body);
if (secret) {
core.info('get secret, sign mode');
}
@@ -406,14 +406,26 @@ function run() {
signKey: secret
});
try {
const resp = yield dingBot.rawSend(data);
const resp = yield dingBot.rawSend(body);
if ((resp === null || resp === void 0 ? void 0 : resp.errcode) !== 0) {
core.setFailed(resp === null || resp === void 0 ? void 0 : resp.errmsg);
if (ignoreError) {
core.warning(resp === null || resp === void 0 ? void 0 : resp.errmsg);
return;
}
else {
core.setFailed(resp === null || resp === void 0 ? void 0 : resp.errmsg);
}
}
}
catch (requestErr) {
core.error(`send request error, status: ${(_a = requestErr.response) === null || _a === void 0 ? void 0 : _a.status}, data: ${(_b = requestErr.response) === null || _b === void 0 ? void 0 : _b.data}`);
core.setFailed(requestErr.message);
if (ignoreError) {
core.warning(requestErr.message);
return;
}
else {
core.setFailed(requestErr.message);
}
}
}
catch (error) {
@@ -655,28 +667,6 @@ exports.getState = getState;
/***/ }),
/***/ 187:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSign = void 0;
const crypto_1 = __webpack_require__(417);
const sha256 = (str, key) => {
const h = crypto_1.createHmac('SHA256', key);
h.update(str);
return h.digest('base64');
};
exports.createSign = (key, ts) => {
const str = `${ts}\n${key}`;
const sign = sha256(str, key);
return encodeURIComponent(sign);
};
//# sourceMappingURL=sign.js.map
/***/ }),
/***/ 211:
/***/ (function(module) {
@@ -1538,6 +1528,28 @@ module.exports = function parseHeaders(headers) {
};
/***/ }),
/***/ 363:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSign = void 0;
const crypto_1 = __webpack_require__(417);
const sha256 = (str, key) => {
const h = crypto_1.createHmac('SHA256', key);
h.update(str);
return h.digest('base64');
};
exports.createSign = (key, ts) => {
const str = `${ts}\n${key}`;
const sign = sha256(str, key);
return encodeURIComponent(sign);
};
//# sourceMappingURL=sign.js.map
/***/ }),
/***/ 402:
@@ -2194,6 +2206,70 @@ module.exports = function isCancel(value) {
};
/***/ }),
/***/ 574:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DingBot = void 0;
const axios_1 = __webpack_require__(452);
const sign_1 = __webpack_require__(363);
const endpoint = 'https://oapi.dingtalk.com/robot/send';
class DingBot {
constructor(options) {
this.options = options;
if (!this.options.endpoint) {
this.options.endpoint = endpoint;
}
}
async sendTextMsg(msg) {
return this.send(msg);
}
async sendLinkMsg(msg) {
return this.send(msg);
}
async sendMarkdownMsg(msg) {
return this.send(msg);
}
async sendActionCardMsg(msg) {
return this.send(msg);
}
async sendFeedCardMsg(msg) {
return this.send(msg);
}
async send(msg) {
const data = await this.rawSend(msg);
if (data.errcode !== 0) {
throw new Error(data.errmsg);
}
}
async rawSend(msg) {
const { data } = await axios_1.default.request({
method: 'post',
url: this.buildUrl(),
data: msg,
headers: {
'content-type': 'application/json',
},
});
return data;
}
buildUrl() {
let url = `${endpoint}?access_token=${this.options.accessToken}`;
if (this.options.signKey) {
const ts = new Date().getTime();
const sign = sign_1.createSign(this.options.signKey, ts);
url += `&timestamp=${ts}&sign=${sign}`;
}
return url;
}
}
exports.DingBot = DingBot;
//# sourceMappingURL=index.js.map
/***/ }),
/***/ 605:
@@ -2500,67 +2576,6 @@ module.exports = require("zlib");
/***/ }),
/***/ 808:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DingBot = void 0;
const axios_1 = __webpack_require__(452);
const sign_1 = __webpack_require__(187);
const endpoint = 'https://oapi.dingtalk.com/robot/send';
class DingBot {
constructor(options) {
this.options = options;
if (!this.options.endpoint) {
this.options.endpoint = endpoint;
}
}
async sendTextMsg(msg) {
return this.send(msg);
}
async sendLinkMsg(msg) {
return this.send(msg);
}
async sendMarkdownMsg(msg) {
return this.send(msg);
}
async sendActionCardMsg(msg) {
return this.send(msg);
}
async sendFeedCardMsg(msg) {
return this.send(msg);
}
async send(msg) {
const data = await this.rawSend(msg);
if (data.errcode !== 0) {
throw new Error(data.errmsg);
}
}
async rawSend(msg) {
const { data } = await axios_1.default.request({
method: 'post',
url: this.buildUrl(),
data: msg,
});
return data;
}
buildUrl() {
let url = `${endpoint}?access_token=${this.options.accessToken}`;
if (this.options.signKey) {
const ts = new Date().getTime();
const sign = sign_1.createSign(this.options.signKey, ts);
url += `&timestamp=${ts}&sign=${sign}`;
}
return url;
}
}
exports.DingBot = DingBot;
//# sourceMappingURL=index.js.map
/***/ }),
/***/ 810:
/***/ (function(module, __unusedexports, __webpack_require__) {
+1 -1
View File
@@ -25,7 +25,7 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.4",
"@zcong/ding-bot": "^0.1.0"
"@zcong/ding-bot": "^0.1.1"
},
"devDependencies": {
"@types/jest": "^26.0.0",
+6 -6
View File
@@ -1,6 +1,6 @@
dependencies:
'@actions/core': registry.npmjs.org/@actions/core/1.2.4
'@zcong/ding-bot': registry.npmjs.org/@zcong/ding-bot/0.1.0
'@zcong/ding-bot': registry.npmjs.org/@zcong/ding-bot/0.1.1
devDependencies:
'@types/jest': registry.npmjs.org/@types/jest/26.0.0
'@types/node': registry.npmjs.org/@types/node/14.0.13
@@ -1043,16 +1043,16 @@ packages:
registry: 'https://registry.npmjs.com/'
tarball: 'https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.3.0.tgz'
version: 3.3.0
registry.npmjs.org/@zcong/ding-bot/0.1.0:
registry.npmjs.org/@zcong/ding-bot/0.1.1:
dependencies:
axios: registry.npmjs.org/axios/0.19.2
dev: false
name: '@zcong/ding-bot'
resolution:
integrity: sha512-2T3cPUb1xnOcLMBi6H3hcscleM5E+UoO+Ly0L2EmLpbZUCYcWSfOBUT+wmHCR345h01s8L+YkjGM5hpBjvGBxQ==
integrity: sha512-vrUa7SjEusjnDvFix4au0pBEPHlmh2tqwAvzPqe/zDKH0eXV9BQr0S6YDhO+mOUigZOppbTqNoq+a33w7fjP/g==
registry: 'https://registry.npmjs.com/'
tarball: 'https://registry.npmjs.org/@zcong/ding-bot/-/ding-bot-0.1.0.tgz'
version: 0.1.0
tarball: 'https://registry.npmjs.org/@zcong/ding-bot/-/ding-bot-0.1.1.tgz'
version: 0.1.1
registry.npmjs.org/@zeit/ncc/0.22.3:
dev: true
hasBin: true
@@ -7318,7 +7318,7 @@ specifiers:
'@types/jest': ^26.0.0
'@types/node': ^14.0.13
'@typescript-eslint/parser': ^3.3.0
'@zcong/ding-bot': ^0.1.0
'@zcong/ding-bot': ^0.1.1
'@zeit/ncc': ^0.22.3
eslint: ^7.2.0
eslint-plugin-github: ^4.0.1
+14 -4
View File
@@ -8,8 +8,8 @@ async function run(): Promise<void> {
const token = core.getInput('dingToken')
const body = core.getInput('body')
const secretStr = core.getInput('secret')
const ignoreError = core.getInput('ignoreError') === 'true'
const secret = secretStr === '' ? undefined : secretStr
const data = JSON.parse(body)
if (secret) {
core.info('get secret, sign mode')
}
@@ -21,16 +21,26 @@ async function run(): Promise<void> {
})
try {
const resp = await dingBot.rawSend(data)
const resp = await dingBot.rawSend(body)
if (resp?.errcode !== 0) {
core.setFailed(resp?.errmsg)
if (ignoreError) {
core.warning(resp?.errmsg)
return
} else {
core.setFailed(resp?.errmsg)
}
}
} catch (requestErr) {
core.error(
`send request error, status: ${requestErr.response?.status}, data: ${requestErr.response?.data}`
)
core.setFailed(requestErr.message)
if (ignoreError) {
core.warning(requestErr.message)
return
} else {
core.setFailed(requestErr.message)
}
}
} catch (error) {
core.setFailed(error.message)