support bot custom note message
This commit is contained in:
@@ -15,4 +15,5 @@ jobs:
|
||||
# BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
|
||||
with:
|
||||
IS_MODIFY_TITLE: true
|
||||
CUSTOM_BOT_NOTE: custom message - Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
+11
-4
@@ -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}`);
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+12
-5
@@ -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}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user