feat: support ignore error and update readme

This commit is contained in:
zcong1993 2020-06-20 23:58:57 +08:00
parent 42205cbb53
commit 6795ef8f80
4 changed files with 43 additions and 5 deletions

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

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'

17
dist/index.js vendored
View File

@ -394,6 +394,7 @@ 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) {
@ -408,12 +409,24 @@ function run() {
try {
const resp = yield dingBot.rawSend(data);
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) {

View File

@ -8,6 +8,7 @@ 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) {
@ -24,13 +25,23 @@ async function run(): Promise<void> {
const resp = await dingBot.rawSend(data)
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)