Skip to content

Commit

Permalink
modify body to string
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxingchun committed Jun 25, 2021
1 parent 6e82930 commit 8c4d3b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions dist/index.js
Expand Up @@ -15561,7 +15561,7 @@ async function run() {
const translateTitle = core.getInput('translate-title') || 'true';
const translateBody = core.getInput('translate-body') || 'true';

if (translateTitle == 'true' && !checkIsEn(title)) {
if (translateTitle == 'true' && containsChinese(title)) {
const { text: newTitle } = await translate(title, { to: 'en' });
core.info(`[translate] [title out: ${newTitle}]`);
await octokit.issues.update({
Expand All @@ -15573,7 +15573,7 @@ async function run() {
core.info(`[update title] [number: ${number}]`);
}

if (translateBody == 'true' && !checkIsEn(body)) {
if (translateBody == 'true' && containsChinese(body)) {
const { text: newBody } = await translate(body, { to: 'en' });
core.info(`[translate] [body out: ${newBody}]`);
await octokit.issues.createComment({
Expand All @@ -15594,12 +15594,11 @@ async function run() {
}
}

function checkIsEn(body) {
var en = /^[a-zA-Z0-9_\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'<>~\路`\?:;|\s]*$/;
const bodyType = typeof body;
function containsChinese(body) {
var patt = /[\u4e00-\u9fa5]/;
const bodyString = body.toString().trim();
const result = en.test(bodyString);
core.info(`[CheckIsEn] [body type is ${bodyType}, ${body} is ${result}]`);
const result = patt.test(bodyString);
core.info(`[containsChinese] [${body} is ${result}]`);
return result;
}

Expand Down
13 changes: 6 additions & 7 deletions src/main.js
Expand Up @@ -31,7 +31,7 @@ async function run() {
const translateTitle = core.getInput('translate-title') || 'true';
const translateBody = core.getInput('translate-body') || 'true';

if (translateTitle == 'true' && !checkIsEn(title)) {
if (translateTitle == 'true' && containsChinese(title)) {
const { text: newTitle } = await translate(title, { to: 'en' });
core.info(`[translate] [title out: ${newTitle}]`);
await octokit.issues.update({
Expand All @@ -43,7 +43,7 @@ async function run() {
core.info(`[update title] [number: ${number}]`);
}

if (translateBody == 'true' && !checkIsEn(body)) {
if (translateBody == 'true' && containsChinese(body)) {
const { text: newBody } = await translate(body, { to: 'en' });
core.info(`[translate] [body out: ${newBody}]`);
await octokit.issues.createComment({
Expand All @@ -64,12 +64,11 @@ async function run() {
}
}

function checkIsEn(body) {
var en = /^[a-zA-Z0-9_\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'<>~\路`\?:;|\s]*$/;
const bodyType = typeof body;
function containsChinese(body) {
var patt = /[\u4e00-\u9fa5]/;
const bodyString = body.toString().trim();
const result = en.test(bodyString);
core.info(`[CheckIsEn] [body type is ${bodyType}, ${body} is ${result}]`);
const result = patt.test(bodyString);
core.info(`[containsChinese] [${body} is ${result}]`);
return result;
}

Expand Down

0 comments on commit 8c4d3b8

Please sign in to comment.