support bot custom note message

This commit is contained in:
tomsun28
2021-03-21 17:44:01 +08:00
parent f3478bebde
commit b0527a12be
5 changed files with 28 additions and 11 deletions
+2 -1
View File
@@ -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. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿
+2
View File
@@ -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'
Generated Vendored
+11 -4
View File
@@ -4622,12 +4622,14 @@ function run() {
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;
issueNumber = issueCommentPayload.issue.number;
issueUser = issueCommentPayload.comment.user.login;
originComment = issueCommentPayload.comment.body;
translateOrigin = originComment;
}
else {
const issuePayload = github.context.payload;
@@ -4635,8 +4637,8 @@ function run() {
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.');
@@ -4652,6 +4654,11 @@ function run() {
botToken = Buffer.from(defaultBotTokenBase64, 'base64').toString();
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);
@@ -4676,11 +4683,11 @@ function run() {
let translateTitle = null;
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}`);
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+12 -5
View File
@@ -22,22 +22,23 @@ async function run(): Promise<void> {
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<void> {
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<void> {
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}`)
}