From b0527a12beb2dd453cf9e691d81945f605f10acd Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sun, 21 Mar 2021 17:44:01 +0800 Subject: [PATCH] support bot custom note message --- .github/workflows/action-test.yml | 3 ++- action.yml | 2 ++ dist/index.js | Bin 570184 -> 570547 bytes dist/index.js.map | Bin 585337 -> 585758 bytes src/main.ts | 17 ++++++++++++----- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/action-test.yml b/.github/workflows/action-test.yml index b411b4c..1ebdca0 100644 --- a/.github/workflows/action-test.yml +++ b/.github/workflows/action-test.yml @@ -14,5 +14,6 @@ jobs: # with: # BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} with: - IS_MODIFY_TITLE: true + IS_MODIFY_TITLE: true + CUSTOM_BOT_NOTE: custom message - Bot detected the issue body's language is not English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ diff --git a/action.yml b/action.yml index 76e7fdd..54b898f 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,8 @@ inputs: description: 'The issue comment bot github login name.' IS_MODIFY_TITLE: description: 'Is need modify issue title, true or false, default false.' + CUSTOM_BOT_NOTE: + description: 'Custom bot note message.' runs: using: 'node12' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index ef2e666563fda23ca2161b639eaff5806ef2ff23..0dab89aeb574ccb109879ba27a6566dd1e3eb13d 100644 GIT binary patch delta 384 zcmX@{Olk8=rG^&97N!>FEi4ngrpt!1@J{#hW#OF83i69e6p~AeOY(CSlJZLw^72bk6>?LHixbmRxfGBLUMjl zs$P0(iDzCxX^Doqb7*jgzi+&ge@MKaf5`L(FBVa2i0MeW6m4x4@=9}Z6x7t9RwE?! zN{TXbH8d4KYLt{FH^z!c0iERsauv`rusacorx$iJ%S^u@z{0Zqe*nuhmgx&-Fp5qO xIKs>a3J2Ed1~sfK(|?7s1b`$YLBXJiszkhfLl_GXvjQ<25VLRJ5XLbh1^}Uje>VUC delta 153 zcmdn|Qt8AqrG^&97N!>FEi4ngrf;~%%(8v27fUqb^!jdQzUkFPtm4xh${E?Vm-w(q zKm{)du&_)Q2xH-#KF)s;EYl0SnPsN?g|kFX oPpW4YntmXhMG+zfHrFPeg}+@Zf(3|KftU@5*|%#&aCF810Pwal8~^|S diff --git a/dist/index.js.map b/dist/index.js.map index e754d60b98c0465b6e02e235f84d1305d659fa71..f626b00c827fde2574b210d1e0d44a7d7ec0bcde 100644 GIT binary patch delta 403 zcmex)M|s`@eH6;cO6*=^Imk!K0VM!a4nDCW{2JI=go1EEXVU1!6WJX5TKI#Szy6 E0P38HS^xk5 delta 163 zcmbRDK>6n#uf|F?xXZN>BrIV>#O zC&#knGETpc#v(X<|2k&&=?8LIgr_GwW9HbN9?zl*l{u5i!aIFt0*k};R|zb0nWz7c zW?|hvE0sl_b^3uUmb&Q*aV( diff --git a/src/main.ts b/src/main.ts index af5a718..a38adf6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,22 +22,23 @@ async function run(): Promise { let issueUser = null let botNote = "Bot detected the issue body's language is not English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ" let isModifyTitle = core.getInput('IS_MODIFY_TITLE') + let translateOrigin = null if (github.context.eventName === 'issue_comment') { const issueCommentPayload = github.context .payload as webhook.EventPayloads.WebhookPayloadIssueComment issueNumber = issueCommentPayload.issue.number issueUser = issueCommentPayload.comment.user.login originComment = issueCommentPayload.comment.body + translateOrigin = originComment } else { const issuePayload = github.context.payload as webhook.EventPayloads.WebhookPayloadIssues issueNumber = issuePayload.issue.number issueUser = issuePayload.issue.user.login originComment = issuePayload.issue.body originTitle = issuePayload.issue.title + translateOrigin = originComment + '@====@' + originTitle } - let translateOrigin = originComment + '@====@' + originTitle - // detect issue title comment body is english if (detectIsEnglish(translateOrigin)) { core.info('Detect the issue comment body is english already, ignore return.') @@ -55,6 +56,12 @@ async function run(): Promise { botLoginName = defaultBotLoginName } + // support custom bot note message + let customBotMessage = core.getInput('CUSTOM_BOT_NOTE') + if (customBotMessage !== null && customBotMessage.trim() !== "") { + botNote = customBotMessage + } + let octokit = null; if (botLoginName === null || botLoginName === undefined || botLoginName === '') { octokit = github.getOctokit(botToken) @@ -85,10 +92,10 @@ async function run(): Promise { core.info(`translate body is: ${translateTmp}`) if (translateBody.length == 1) { - translateComment = translateBody[0] + translateComment = translateBody[0].trim() } else if (translateBody.length == 2) { - translateComment = translateBody[0] - translateTitle = translateBody[1] + translateComment = translateBody[0].trim() + translateTitle = translateBody[1].trim() } else { core.setFailed(`the translateBody is ${translateTmp}`) } -- GitLab