Compare commits
No commits in common. "master" and "v2" have entirely different histories.
|
@ -1,3 +0,0 @@
|
|||
dist/
|
||||
lib/
|
||||
node_modules/
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"plugins": ["jest", "@typescript-eslint"],
|
||||
"extends": ["plugin:github/typescript"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
// "@typescript-eslint/ban-ts-ignore": "error",
|
||||
"camelcase": "off",
|
||||
// "@typescript-eslint/camelcase": "error",
|
||||
// "@typescript-eslint/class-name-casing": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
// "@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
// "@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
// "@typescript-eslint/no-object-literal-type-assertion": "error",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
// "@typescript-eslint/prefer-interface": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": ["error", "never"],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest/globals": true
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
name: Test
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
# test action works running from the graph
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Send dingding notify
|
||||
uses: ./
|
||||
with:
|
||||
dingToken: ${{ secrets.DING_TOKEN }}
|
||||
secret: ${{ secrets.DING_SECRET }} # if secret set, action will call API with sign
|
||||
body: |
|
||||
{
|
||||
"msgtype": "link",
|
||||
"link": {
|
||||
"text": "这个即将发布的新版本,创始人陈航(花名“无招”)称它为“红树林”。而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是“红树林”?",
|
||||
"title": "时代的火车向前开",
|
||||
"picUrl": "",
|
||||
"messageUrl": "https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI"
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
node_modules
|
|
@ -1,3 +0,0 @@
|
|||
dist/
|
||||
lib/
|
||||
node_modules/
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
33
README.md
33
README.md
|
@ -1,18 +1,7 @@
|
|||
# DingDing Notify Action [![Test](https://github.com/zcong1993/actions-ding/actions/workflows/test.yml/badge.svg)](https://github.com/zcong1993/actions-ding/actions/workflows/test.yml)
|
||||
# DingDing Notify Action
|
||||
|
||||
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
|
||||
|
@ -30,24 +19,4 @@ Send dingding simple notify message.
|
|||
}
|
||||
```
|
||||
|
||||
### with sign
|
||||
|
||||
```yaml
|
||||
- name: Send dingding notify
|
||||
uses: zcong1993/actions-ding@master
|
||||
with:
|
||||
dingToken: ${{ secrets.DING_TOKEN }}
|
||||
secret: ${{ secrets.DING_SECRET }} # if secret set, action will call API with sign
|
||||
body: |
|
||||
{
|
||||
"msgtype": "link",
|
||||
"link": {
|
||||
"text": "这个即将发布的新版本,创始人陈航(花名“无招”)称它为“红树林”。而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是“红树林”?",
|
||||
"title": "时代的火车向前开",
|
||||
"picUrl": "",
|
||||
"messageUrl": "https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
put any kind of message body [dingding](https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq) support into `body` field.
|
||||
|
|
10
action.yml
10
action.yml
|
@ -11,13 +11,7 @@ inputs:
|
|||
body:
|
||||
description: 'Post Body to send'
|
||||
required: true
|
||||
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: 'node16'
|
||||
main: 'dist/index.js'
|
||||
using: 'docker'
|
||||
image: 'docker://zcong/actions-ding:latest'
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,5 @@
|
|||
FROM appropriate/curl:latest
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh -l
|
||||
|
||||
if [ -z "${INPUT_DINGTOKEN}" ]
|
||||
then
|
||||
echo "dingToken is required!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${INPUT_BODY}" ]
|
||||
then
|
||||
echo "body is required!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "body: $INPUT_BODY"
|
||||
|
||||
url="https://oapi.dingtalk.com/robot/send?access_token=${INPUT_DINGTOKEN}"
|
||||
|
||||
HTTP_RESPONSE=$(curl -s --write-out "HTTPSTATUS:%{http_code}" "$url" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "${INPUT_BODY}")
|
||||
|
||||
# extract the body
|
||||
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
|
||||
|
||||
if [ ! "$HTTP_BODY" = '{"errcode":0,"errmsg":"ok"}' ]; then
|
||||
echo "Error Response: ${HTTP_RESPONSE}"
|
||||
exit 1
|
||||
fi
|
|
@ -1,57 +0,0 @@
|
|||
name: Build
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
Build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Private Actions Checkout
|
||||
uses: actions/checkout@v2
|
||||
### show time now
|
||||
####
|
||||
####
|
||||
-
|
||||
name: Get Data
|
||||
id: getDingData
|
||||
run: |
|
||||
# 输出仓库名
|
||||
REPOSITORY="${{GITHUB.REPOSITORY}}"
|
||||
echo "::set-output name=REPOSITORY::${REPOSITORY#*/}"
|
||||
|
||||
# 获取用户仓库信息
|
||||
RESPONSE="$(curl -sLm 10 https://api.github.com/repos/${{ GITHUB.REPOSITORY }})"
|
||||
# 建议填写自己的 TOKEN
|
||||
# RESPONSE="$(curl -sLm 10 https://api.github.com/repos/${{ GITHUB.REPOSITORY }} -H "Authorization: token ${{ SECRETS.TOKEN_GITHUB }}")"
|
||||
|
||||
# 获取 用户仓库 设置的 描述,如果为空,可能是没有使用 TOKEN
|
||||
DESCRIPTION="$(jq -r .description <(echo ${RESPONSE}))"
|
||||
echo "::set-output name=DESCRIPTION::${DESCRIPTION}"
|
||||
|
||||
# 获取 用户仓库 设置的 URL, 如果没有就输出 Github 地址
|
||||
URL="$(jq -r .homepage <(echo ${RESPONSE}))"
|
||||
if [[ "${URL}" != "null" || "${URL}" != "" ]]; then
|
||||
echo "::set-output name=URL::${URL}"
|
||||
else
|
||||
echo "::set-output name=URL::${{ GITHUB.SERVER_URL }}/${{ GITHUB.REPOSITORY }}"
|
||||
fi
|
||||
-
|
||||
name: Send dingding notify
|
||||
uses: zcong1993/actions-ding@master
|
||||
with:
|
||||
dingToken: ${{ SECRETS.DING_TOKEN }}
|
||||
secret: ${{ SECRETS.DING_SECRET }}
|
||||
body: |
|
||||
{
|
||||
"msgtype": "link",
|
||||
"link": {
|
||||
"text": "${{ steps.getDingData.outputs.DESCRIPTION }}",
|
||||
"title": "${{ steps.getDingData.outputs.REPOSITORY }} WorkFlow ${{ GITHUB.JOB }} Success!",
|
||||
"picUrl": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
|
||||
"messageUrl": "${{ steps.getDingData.outputs.URL }}"
|
||||
}
|
||||
}
|
42
package.json
42
package.json
|
@ -1,42 +0,0 @@
|
|||
{
|
||||
"name": "actions-ding",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"description": "Send dingding simple notify message",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"package": "ncc build src/index.ts -o dist",
|
||||
"test": "jest",
|
||||
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zcong1993/actions-ding"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"node",
|
||||
"setup"
|
||||
],
|
||||
"author": "zcong1993",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.6.0",
|
||||
"@zcong/ding-bot": "^0.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "^16.11.7",
|
||||
"@typescript-eslint/parser": "^5.3.1",
|
||||
"@vercel/ncc": "^0.31.1",
|
||||
"eslint": "^8.2.0",
|
||||
"eslint-plugin-github": "^4.3.4",
|
||||
"eslint-plugin-jest": "^25.2.4",
|
||||
"jest": "^27.3.1",
|
||||
"prettier": "^2.4.1",
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
3820
pnpm-lock.yaml
3820
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
50
src/index.ts
50
src/index.ts
|
@ -1,50 +0,0 @@
|
|||
import * as core from '@actions/core'
|
||||
import {DingBot} from '@zcong/ding-bot'
|
||||
|
||||
const endpoint = 'https://oapi.dingtalk.com/robot/send'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
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
|
||||
if (secret) {
|
||||
core.info('get secret, sign mode')
|
||||
}
|
||||
core.info(`Send body: ${body}`)
|
||||
const dingBot = new DingBot({
|
||||
endpoint,
|
||||
accessToken: token,
|
||||
signKey: secret
|
||||
})
|
||||
|
||||
try {
|
||||
const resp = await dingBot.rawSend(body)
|
||||
|
||||
if (resp?.errcode !== 0) {
|
||||
if (ignoreError) {
|
||||
core.warning(resp?.errmsg)
|
||||
return
|
||||
} else {
|
||||
core.setFailed(resp?.errmsg)
|
||||
}
|
||||
}
|
||||
} catch (requestErr: any) {
|
||||
core.error(
|
||||
`send request error, status: ${requestErr.response?.status}, data: ${requestErr.response?.data}`
|
||||
)
|
||||
if (ignoreError) {
|
||||
core.warning(requestErr.message)
|
||||
return
|
||||
} else {
|
||||
core.setFailed(requestErr.message)
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
Loading…
Reference in New Issue