From 6795ef8f8043c9a247f4bcf403ba49cf9fc281df Mon Sep 17 00:00:00 2001 From: zcong1993 Date: Sat, 20 Jun 2020 23:58:57 +0800 Subject: [PATCH] feat: support ignore error and update readme --- README.md | 13 ++++++++++++- action.yml | 3 +++ dist/index.js | 17 +++++++++++++++-- src/index.ts | 15 +++++++++++++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a67f506..2833e56 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index f00acb6..32f63c5 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/dist/index.js b/dist/index.js index 4b1c26d..7878a06 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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) { diff --git a/src/index.ts b/src/index.ts index 2630163..85cd41c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ async function run(): Promise { 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 { 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)