2020-06-19 15:57:43 +08:00
|
|
|
import * as core from '@actions/core'
|
2020-06-19 17:25:50 +08:00
|
|
|
import {DingBot} from '@zcong/ding-bot'
|
2020-06-19 15:57:43 +08:00
|
|
|
|
|
|
|
|
const endpoint = 'https://oapi.dingtalk.com/robot/send'
|
|
|
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
|
try {
|
2020-06-19 17:25:50 +08:00
|
|
|
const token = core.getInput('dingToken')
|
|
|
|
|
const body = core.getInput('body')
|
|
|
|
|
const secretStr = core.getInput('secret')
|
2020-06-20 23:58:57 +08:00
|
|
|
const ignoreError = core.getInput('ignoreError') === 'true'
|
2020-06-19 17:25:50 +08:00
|
|
|
const secret = secretStr === '' ? undefined : secretStr
|
|
|
|
|
if (secret) {
|
|
|
|
|
core.info('get secret, sign mode')
|
|
|
|
|
}
|
2020-06-19 16:00:51 +08:00
|
|
|
core.info(`Send body: ${body}`)
|
2020-06-19 17:25:50 +08:00
|
|
|
const dingBot = new DingBot({
|
|
|
|
|
endpoint,
|
|
|
|
|
accessToken: token,
|
|
|
|
|
signKey: secret
|
|
|
|
|
})
|
|
|
|
|
|
2020-06-19 15:57:43 +08:00
|
|
|
try {
|
2020-07-06 00:58:55 +08:00
|
|
|
const resp = await dingBot.rawSend(body)
|
2020-06-19 15:57:43 +08:00
|
|
|
|
2020-06-19 17:25:50 +08:00
|
|
|
if (resp?.errcode !== 0) {
|
2020-06-20 23:58:57 +08:00
|
|
|
if (ignoreError) {
|
|
|
|
|
core.warning(resp?.errmsg)
|
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
core.setFailed(resp?.errmsg)
|
|
|
|
|
}
|
2020-06-19 15:57:43 +08:00
|
|
|
}
|
2021-11-08 10:55:31 +08:00
|
|
|
} catch (requestErr: any) {
|
2020-06-19 15:57:43 +08:00
|
|
|
core.error(
|
|
|
|
|
`send request error, status: ${requestErr.response?.status}, data: ${requestErr.response?.data}`
|
|
|
|
|
)
|
2020-06-20 23:58:57 +08:00
|
|
|
if (ignoreError) {
|
|
|
|
|
core.warning(requestErr.message)
|
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
core.setFailed(requestErr.message)
|
|
|
|
|
}
|
2020-06-19 15:57:43 +08:00
|
|
|
}
|
2021-11-08 10:55:31 +08:00
|
|
|
} catch (error: any) {
|
2020-06-19 15:57:43 +08:00
|
|
|
core.setFailed(error.message)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
run()
|