This commit is contained in:
zcong1993 2020-06-19 15:57:43 +08:00
parent 13a3e4afd9
commit 1b3399a065
13 changed files with 11307 additions and 36 deletions

3
.eslintignore Normal file
View File

@ -0,0 +1,3 @@
dist/
lib/
node_modules/

58
.eslintrc.json Normal file
View File

@ -0,0 +1,58 @@
{
"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
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

3
.prettierignore Normal file
View File

@ -0,0 +1,3 @@
dist/
lib/
node_modules/

11
.prettierrc.json Normal file
View File

@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

View File

@ -13,5 +13,5 @@ inputs:
required: true required: true
runs: runs:
using: 'docker' using: 'node12'
image: 'docker://zcong/actions-ding:latest' main: 'dist/index.js'

3822
dist/index.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +0,0 @@
FROM appropriate/curl:latest
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -1,29 +0,0 @@
#!/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

42
package.json Normal file
View File

@ -0,0 +1,42 @@
{
"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",
"pack": "ncc build src/index.ts -o dist",
"test": "jest",
"all": "npm run build && npm run format && npm run lint && npm run pack && 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.2.4",
"axios": "^0.19.2"
},
"devDependencies": {
"@types/jest": "^26.0.0",
"@types/node": "^14.0.13",
"@typescript-eslint/parser": "^3.3.0",
"@zeit/ncc": "^0.22.3",
"eslint": "^7.2.0",
"eslint-plugin-github": "^4.0.1",
"eslint-plugin-jest": "^23.13.2",
"jest": "^26.0.1",
"prettier": "^2.0.5",
"typescript": "^3.9.5"
}
}

7318
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

35
src/index.ts Normal file
View File

@ -0,0 +1,35 @@
import * as core from '@actions/core'
import axios from 'axios'
const endpoint = 'https://oapi.dingtalk.com/robot/send'
async function run(): Promise<void> {
try {
const token: string = core.getInput('dingToken')
const body: string = core.getInput('body')
core.debug(`Send body: ${body}`)
try {
const resp = await axios({
method: 'post',
url: `${endpoint}?access_token=${token}`,
data: body,
headers: {
'Content-Type': 'application/json'
}
})
if (resp.data.errcode !== 0) {
core.setFailed(resp.data?.errmsg)
}
} catch (requestErr) {
core.error(
`send request error, status: ${requestErr.response?.status}, data: ${requestErr.response?.data}`
)
core.setFailed(requestErr.message)
}
} catch (error) {
core.setFailed(error.message)
}
}
run()

12
tsconfig.json Normal file
View File

@ -0,0 +1,12 @@
{
"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"]
}