提交 69ba877c 编写于 作者: sinat_25235033's avatar sinat_25235033

fin action, todo more test

上级 6a7ebaea
name: 'build-test'
on: # rebuild any PRs and main branch changes
issues:
issue_comment:
branches:
- main
......@@ -21,4 +20,5 @@ jobs:
- uses: actions/checkout@v2
- uses: ./
with:
bot_github_token: ${{ secrets.BOT_GITHUB_TOKEN }}
milliseconds: 1000
......@@ -1506,6 +1506,14 @@
"@types/yargs": "^13.0.0"
}
},
"@k3rn31p4nic/google-translate-api": {
"version": "1.1.1",
"resolved": "https://registry.npm.taobao.org/@k3rn31p4nic/google-translate-api/download/@k3rn31p4nic/google-translate-api-1.1.1.tgz",
"integrity": "sha1-OGmFT3VAu7gq/BthiQKB9VE+Fxc=",
"requires": {
"got": "^11.1.1"
}
},
"@octokit/auth-token": {
"version": "2.4.3",
"resolved": "https://registry.npm.taobao.org/@octokit/auth-token/download/@octokit/auth-token-2.4.3.tgz",
......@@ -1722,6 +1730,11 @@
"resolved": "https://registry.npm.taobao.org/@pika/types/download/@pika/types-0.9.2.tgz",
"integrity": "sha1-YK0Wr+EpOHgjLiiTfZAHNAxZ/3w="
},
"@sindresorhus/is": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/@sindresorhus/is/download/@sindresorhus/is-4.0.0.tgz?cache=0&sync_timestamp=1602540879975&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40sindresorhus%2Fis%2Fdownload%2F%40sindresorhus%2Fis-4.0.0.tgz",
"integrity": "sha1-L/Z06WEbRbUoiW2CDT16gS3i8OQ="
},
"@sinonjs/commons": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.1.tgz",
......@@ -1740,6 +1753,14 @@
"@sinonjs/commons": "^1.7.0"
}
},
"@szmarczak/http-timer": {
"version": "4.0.5",
"resolved": "https://registry.npm.taobao.org/@szmarczak/http-timer/download/@szmarczak/http-timer-4.0.5.tgz",
"integrity": "sha1-v71QIR6d+lG6B9pYoUzf0zMgUVI=",
"requires": {
"defer-to-connect": "^2.0.0"
}
},
"@types/babel__core": {
"version": "7.1.3",
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.3.tgz",
......@@ -1781,6 +1802,17 @@
"@babel/types": "^7.3.0"
}
},
"@types/cacheable-request": {
"version": "6.0.1",
"resolved": "https://registry.npm.taobao.org/@types/cacheable-request/download/@types/cacheable-request-6.0.1.tgz",
"integrity": "sha1-XSLz3e0f06hMC761A5p0GcLJGXY=",
"requires": {
"@types/http-cache-semantics": "*",
"@types/keyv": "*",
"@types/node": "*",
"@types/responselike": "*"
}
},
"@types/color-name": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
......@@ -1802,6 +1834,11 @@
"@types/node": "*"
}
},
"@types/http-cache-semantics": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/@types/http-cache-semantics/download/@types/http-cache-semantics-4.0.0.tgz",
"integrity": "sha1-kUB3lzaqJlVjXudW4kZ9eHz+iio="
},
"@types/istanbul-lib-coverage": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz",
......@@ -1964,6 +2001,14 @@
"integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=",
"dev": true
},
"@types/keyv": {
"version": "3.1.1",
"resolved": "https://registry.npm.taobao.org/@types/keyv/download/@types/keyv-3.1.1.tgz",
"integrity": "sha1-5FpFMk/KnatxarEjDuJJyftSz6c=",
"requires": {
"@types/node": "*"
}
},
"@types/minimist": {
"version": "1.2.1",
"resolved": "https://registry.npm.taobao.org/@types/minimist/download/@types/minimist-1.2.1.tgz",
......@@ -1986,6 +2031,14 @@
"integrity": "sha512-hiYA88aHiEIgDmeKlsyVsuQdcFn3Z2VuFd/Xm/HCnGnPD8UFU5BM128uzzRVVGEzKDKYUrRsRH9S2o+NUy/3IA==",
"dev": true
},
"@types/responselike": {
"version": "1.0.0",
"resolved": "https://registry.npm.taobao.org/@types/responselike/download/@types/responselike-1.0.0.tgz",
"integrity": "sha1-JR9P59FU0rrRJavhtCmyOv0mLik=",
"requires": {
"@types/node": "*"
}
},
"@types/stack-utils": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz",
......@@ -2727,6 +2780,35 @@
"unset-value": "^1.0.0"
}
},
"cacheable-lookup": {
"version": "5.0.3",
"resolved": "https://registry.npm.taobao.org/cacheable-lookup/download/cacheable-lookup-5.0.3.tgz",
"integrity": "sha1-BJ/cWd/91PwoXo9PgpNlkb1Z/sM="
},
"cacheable-request": {
"version": "7.0.1",
"resolved": "https://registry.npm.taobao.org/cacheable-request/download/cacheable-request-7.0.1.tgz",
"integrity": "sha1-BiAxwoViMngu1pSiV/o12pOUKlg=",
"requires": {
"clone-response": "^1.0.2",
"get-stream": "^5.1.0",
"http-cache-semantics": "^4.0.0",
"keyv": "^4.0.0",
"lowercase-keys": "^2.0.0",
"normalize-url": "^4.1.0",
"responselike": "^2.0.0"
},
"dependencies": {
"get-stream": {
"version": "5.2.0",
"resolved": "https://registry.npm.taobao.org/get-stream/download/get-stream-5.2.0.tgz",
"integrity": "sha1-SWaheV7lrOZecGxLe+txJX1uItM=",
"requires": {
"pump": "^3.0.0"
}
}
}
},
"callsites": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
......@@ -2831,6 +2913,14 @@
}
}
},
"clone-response": {
"version": "1.0.2",
"resolved": "https://registry.npm.taobao.org/clone-response/download/clone-response-1.0.2.tgz",
"integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=",
"requires": {
"mimic-response": "^1.0.0"
}
},
"co": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
......@@ -3007,6 +3097,21 @@
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
"dev": true
},
"decompress-response": {
"version": "6.0.0",
"resolved": "https://registry.npm.taobao.org/decompress-response/download/decompress-response-6.0.0.tgz",
"integrity": "sha1-yjh2Et234QS9FthaqwDV7PCcZvw=",
"requires": {
"mimic-response": "^3.1.0"
},
"dependencies": {
"mimic-response": {
"version": "3.1.0",
"resolved": "https://registry.npm.taobao.org/mimic-response/download/mimic-response-3.1.0.tgz",
"integrity": "sha1-LR1Zr5wbEpgVrMwsRqAipc4fo8k="
}
}
},
"dedent": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz",
......@@ -3025,6 +3130,11 @@
"integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==",
"dev": true
},
"defer-to-connect": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/defer-to-connect/download/defer-to-connect-2.0.0.tgz",
"integrity": "sha1-g9axmdsEFZOshNeBtSIjCMz0wsE="
},
"define-properties": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
......@@ -4708,6 +4818,24 @@
"resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
"integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA=="
},
"got": {
"version": "11.8.0",
"resolved": "https://registry.npm.taobao.org/got/download/got-11.8.0.tgz?cache=0&sync_timestamp=1603212362718&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fgot%2Fdownload%2Fgot-11.8.0.tgz",
"integrity": "sha1-vgkgw1hrB/2UrdO1snyyj0nmVF8=",
"requires": {
"@sindresorhus/is": "^4.0.0",
"@szmarczak/http-timer": "^4.0.5",
"@types/cacheable-request": "^6.0.1",
"@types/responselike": "^1.0.0",
"cacheable-lookup": "^5.0.3",
"cacheable-request": "^7.0.1",
"decompress-response": "^6.0.0",
"http2-wrapper": "^1.0.0-beta.5.2",
"lowercase-keys": "^2.0.0",
"p-cancelable": "^2.0.0",
"responselike": "^2.0.0"
}
},
"graceful-fs": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz",
......@@ -4809,6 +4937,11 @@
"integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==",
"dev": true
},
"http-cache-semantics": {
"version": "4.1.0",
"resolved": "https://registry.npm.taobao.org/http-cache-semantics/download/http-cache-semantics-4.1.0.tgz",
"integrity": "sha1-SekcXL82yblLz81xwj1SSex045A="
},
"http-signature": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
......@@ -4820,6 +4953,15 @@
"sshpk": "^1.7.0"
}
},
"http2-wrapper": {
"version": "1.0.0-beta.5.2",
"resolved": "https://registry.npm.taobao.org/http2-wrapper/download/http2-wrapper-1.0.0-beta.5.2.tgz",
"integrity": "sha1-i5I965AUSuplz4NLAWo0D8mFVvM=",
"requires": {
"quick-lru": "^5.1.1",
"resolve-alpn": "^1.0.0"
}
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
......@@ -7281,6 +7423,11 @@
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
"integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA=="
},
"json-buffer": {
"version": "3.0.1",
"resolved": "https://registry.npm.taobao.org/json-buffer/download/json-buffer-3.0.1.tgz",
"integrity": "sha1-kziAKjDTtmBfvgYT4JQAjKjAWhM="
},
"json-parse-better-errors": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz",
......@@ -7344,6 +7491,14 @@
"verror": "1.10.0"
}
},
"keyv": {
"version": "4.0.3",
"resolved": "https://registry.npm.taobao.org/keyv/download/keyv-4.0.3.tgz?cache=0&sync_timestamp=1600337464891&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fkeyv%2Fdownload%2Fkeyv-4.0.3.tgz",
"integrity": "sha1-TzqpjeJUgDyvzSiWc0EI2qNeQlQ=",
"requires": {
"json-buffer": "3.0.1"
}
},
"kind-of": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
......@@ -7358,8 +7513,8 @@
},
"languagedetect": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/languagedetect/download/languagedetect-2.0.0.tgz",
"integrity": "sha1-S4+it1k7KjoC+xEAiRBBxTI4k2w="
"resolved": "https://registry.npmjs.org/languagedetect/-/languagedetect-2.0.0.tgz",
"integrity": "sha512-AZb/liiQ+6ZoTj4f1J0aE6OkzhCo8fyH+tuSaPfSo8YHCWLFJrdSixhtO2TYdIkjcDQNaR4RmGaV2A5FJklDMQ=="
},
"left-pad": {
"version": "1.3.0",
......@@ -7437,6 +7592,11 @@
"js-tokens": "^3.0.0 || ^4.0.0"
}
},
"lowercase-keys": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/lowercase-keys/download/lowercase-keys-2.0.0.tgz",
"integrity": "sha1-JgPni3tLAAbLyi+8yKMgJVislHk="
},
"make-dir": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz",
......@@ -7537,6 +7697,11 @@
"resolved": "https://registry.npm.taobao.org/mimic-fn/download/mimic-fn-2.1.0.tgz",
"integrity": "sha1-ftLCzMyvhNP/y3pptXcR/CCDQBs="
},
"mimic-response": {
"version": "1.0.1",
"resolved": "https://registry.npm.taobao.org/mimic-response/download/mimic-response-1.0.1.tgz",
"integrity": "sha1-SSNTiHju9CBjy4o+OweYeBSHqxs="
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
......@@ -7696,6 +7861,11 @@
"remove-trailing-separator": "^1.0.1"
}
},
"normalize-url": {
"version": "4.5.0",
"resolved": "https://registry.npm.taobao.org/normalize-url/download/normalize-url-4.5.0.tgz",
"integrity": "sha1-RTNUCH5sqWlXvY9br3U/WYIUISk="
},
"npm-run-path": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
......@@ -7878,6 +8048,11 @@
"word-wrap": "~1.2.3"
}
},
"p-cancelable": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/p-cancelable/download/p-cancelable-2.0.0.tgz",
"integrity": "sha1-SjdA9b2vXtXXw+NIgsb7XWsmam4="
},
"p-each-series": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-each-series/-/p-each-series-1.0.0.tgz",
......@@ -8108,6 +8283,11 @@
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==",
"dev": true
},
"quick-lru": {
"version": "5.1.1",
"resolved": "https://registry.npm.taobao.org/quick-lru/download/quick-lru-5.1.1.tgz",
"integrity": "sha1-NmST5rPkKjpoheLpnRj4D7eoyTI="
},
"react-is": {
"version": "16.12.0",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.12.0.tgz",
......@@ -8357,6 +8537,11 @@
"path-parse": "^1.0.6"
}
},
"resolve-alpn": {
"version": "1.0.0",
"resolved": "https://registry.npm.taobao.org/resolve-alpn/download/resolve-alpn-1.0.0.tgz",
"integrity": "sha1-dFrWCz1q/0tKSOAbjAvccJWeDow="
},
"resolve-cwd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-2.0.0.tgz",
......@@ -8386,6 +8571,14 @@
"integrity": "sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=",
"dev": true
},
"responselike": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/responselike/download/responselike-2.0.0.tgz",
"integrity": "sha1-JjkbzDF091D5p56sxAoSpcQtdyM=",
"requires": {
"lowercase-keys": "^2.0.0"
}
},
"ret": {
"version": "0.1.15",
"resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz",
......
......@@ -11,7 +11,7 @@
"lint": "eslint src/**/*.ts",
"package": "ncc build --source-map --license licenses.txt",
"test": "jest",
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
"all": "npm run build && npm run format && npm run package && npm test"
},
"repository": {
"type": "git",
......@@ -27,6 +27,7 @@
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"@k3rn31p4nic/google-translate-api": "^1.1.1",
"@octokit/webhooks": "^7.15.1",
"languagedetect": "^2.0.0"
},
......
import * as core from '@actions/core'
import {wait} from './wait'
import * as github from '@actions/github'
import * as webhook from '@octokit/webhooks'
import LanguageDetect from 'languagedetect'
import translate from '@k3rn31p4nic/google-translate-api'
async function run(): Promise<void> {
try {
core.info(JSON.stringify(github.context))
if (
github.context.payload.action &&
!['created', 'opened'].includes(github.context.payload.action)
github.context.eventName !== 'issue_comment' ||
github.context.payload.action ||
github.context.payload.action !== 'created'
) {
core.info(
`The status of the action is no applicable ${github.context.payload.action}, return`
core.setFailed(
`The status of the action must be created on issue_comment, no applicable - ${github.context.payload.action} on ${github.context.eventName}, return`
)
return
}
if (github.context.eventName === 'issue') {
const issuePayload = github.context
.payload as webhook.EventPayloads.WebhookPayloadIssues
core.info(JSON.stringify(issuePayload))
} else if (github.context.eventName === 'issue_comment') {
const issueCommentPayload = github.context
.payload as webhook.EventPayloads.WebhookPayloadIssueComment
core.info(JSON.stringify(issueCommentPayload))
} else {
core.info(JSON.stringify(github.context.payload))
}
const ms: string = core.getInput('milliseconds')
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
const issueCommentPayload = github.context
.payload as webhook.EventPayloads.WebhookPayloadIssueComment
core.info(JSON.stringify(issueCommentPayload))
const issue_id = issueCommentPayload.issue.id
const issue_origin_comment_body = issueCommentPayload.comment.body
core.info(issue_origin_comment_body)
let issue_translate_comment_body = null
core.debug(new Date().toTimeString())
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())
// detect comment body is english
if (detectIsEnglish(issue_origin_comment_body)) {
core.info('the issue comment body is english already.')
return
}
issue_translate_comment_body = await translateCommentBody(
issue_origin_comment_body
)
core.info(issue_translate_comment_body)
await createComment(issue_id, issue_translate_comment_body)
core.setOutput('time', new Date().toTimeString())
} catch (error) {
core.setFailed(error.message)
}
}
function detectIsEnglish(body: string): boolean | true {
const lngDetector = new LanguageDetect()
const detectResult = lngDetector.detect(body, 1)
return detectResult.length === 1 && detectResult[0][0] === 'english'
}
async function translateCommentBody(body: string): Promise<string> {
let result = ''
await translate(body, {to: 'en'})
.then(res => {
core.info(res.text)
result = res.text
})
.catch(err => {
core.error(err)
core.setFailed(err.message)
})
return result
}
async function createComment(issueId: number, body: string): Promise<void> {
const {owner, repo} = github.context.repo
const myToken = core.getInput('bot_github_token')
const octokit = github.getOctokit(myToken)
await octokit.issues.createComment({
owner,
repo,
['issue_number']: issueId,
body
})
}
run()
export async function wait(milliseconds: number): Promise<string> {
return new Promise(resolve => {
if (isNaN(milliseconds)) {
throw new Error('milliseconds not a number')
}
setTimeout(() => resolve('done!'), milliseconds)
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册