Copilot commented on code in PR #1102:
URL: 
https://github.com/apache/incubator-seata-go/pull/1102#discussion_r3037112337


##########
.github/workflows/issue-robot.yml:
##########
@@ -22,12 +22,94 @@ on:
   issues:
     types: [opened]
 
+permissions:
+  issues: write
+
 jobs:
-  build:
+  translate:
     runs-on: ubuntu-latest
     steps:
-      - uses: tomsun28/[email protected]
+      - uses: actions/github-script@v7
         with:
-          # it is not necessary to decide whether you need to modify the issue 
header content
-          IS_MODIFY_TITLE: false
-          CUSTOM_BOT_NOTE: RoBot detected the issue body's language is not 
English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ
+          script: |
+            const isComment = context.eventName === 'issue_comment';
+            const text = isComment
+              ? context.payload.comment.body
+              : context.payload.issue.body;
+
+            if (!text || !text.trim()) return;
+
+            // Skip bot users and our own translation comments
+            const actor = isComment ? context.payload.comment.user : 
context.payload.issue.user;
+            if (actor.type === 'Bot') return;
+            if (text.startsWith('> Bot detected the issue body')) return;
+
+            // Quick heuristic: low non-ASCII ratio means likely English
+            const nonAscii = (text.match(/[^\x00-\x7F]/g) || []).length;
+            if (nonAscii / text.length < 0.1) return;
+
+            // Detect source language from Unicode character ranges
+            const cjk = (text.match(/[\u4e00-\u9fff]/g) || []).length;
+            const kana = (text.match(/[\u3040-\u30ff]/g) || []).length;
+            const hangul = (text.match(/[\uac00-\ud7af]/g) || []).length;
+            const cyrillic = (text.match(/[\u0400-\u04ff]/g) || []).length;
+
+            let srcLang = 'zh-CN';
+            if (kana > cjk * 0.1) srcLang = 'ja';
+            else if (hangul > cjk) srcLang = 'ko';
+            else if (cyrillic > cjk) srcLang = 'ru';
+

Review Comment:
   `srcLang` defaults to `zh-CN` unless the text matches a few specific Unicode 
ranges. For many non-English languages that aren’t CJK/Kana/Hangul/Cyrillic 
(e.g., Spanish with accents, Arabic, Hindi), this will pick the wrong source 
language and produce incorrect translations. Consider adding broader detection 
(or using an API mode that supports auto-detect) and only defaulting to zh-CN 
when there’s clear evidence of Chinese text.
   ```suggestion
               // Detect source language from Unicode character ranges.
               // Only use zh-CN when there is clear evidence of Han text;
               // otherwise prefer a script-specific language or skip 
translation.
               const cjk = 
(text.match(/[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]/g) || []).length;
               const kana = (text.match(/[\u3040-\u30ff]/g) || []).length;
               const hangul = (text.match(/[\uac00-\ud7af]/g) || []).length;
               const cyrillic = (text.match(/[\u0400-\u04ff]/g) || []).length;
               const arabic = 
(text.match(/[\u0600-\u06ff\u0750-\u077f\u08a0-\u08ff]/g) || []).length;
               const devanagari = (text.match(/[\u0900-\u097f]/g) || []).length;
               const hebrew = (text.match(/[\u0590-\u05ff]/g) || []).length;
               const greek = (text.match(/[\u0370-\u03ff]/g) || []).length;
               const thai = (text.match(/[\u0e00-\u0e7f]/g) || []).length;
   
               let srcLang = null;
               if (kana > cjk * 0.1) srcLang = 'ja';
               else if (hangul > cjk) srcLang = 'ko';
               else if (cyrillic > 0) srcLang = 'ru';
               else if (arabic > 0) srcLang = 'ar';
               else if (devanagari > 0) srcLang = 'hi';
               else if (hebrew > 0) srcLang = 'he';
               else if (greek > 0) srcLang = 'el';
               else if (thai > 0) srcLang = 'th';
               else if (cjk > 0) srcLang = 'zh-CN';
   
               if (!srcLang) {
                 core.info('Skipping translation: unable to determine a 
supported non-English source language.');
                 return;
               }
   ```



##########
.github/workflows/issue-robot.yml:
##########
@@ -22,12 +22,94 @@ on:
   issues:
     types: [opened]
 
+permissions:
+  issues: write
+
 jobs:
-  build:
+  translate:
     runs-on: ubuntu-latest
     steps:
-      - uses: tomsun28/[email protected]
+      - uses: actions/github-script@v7
         with:

Review Comment:
   This workflow will still run for bot-authored comments (including the bot’s 
own translation comment) and only exits inside the script, which still consumes 
an Actions run. Consider adding a job- or step-level condition (e.g., `if: 
github.actor != 'github-actions[bot]'` and/or checking for `Bot` actors) to 
avoid starting the job for bot events at all.



##########
.github/workflows/issue-robot.yml:
##########
@@ -22,12 +22,94 @@ on:
   issues:
     types: [opened]
 
+permissions:
+  issues: write
+
 jobs:
-  build:
+  translate:
     runs-on: ubuntu-latest
     steps:
-      - uses: tomsun28/[email protected]
+      - uses: actions/github-script@v7
         with:
-          # it is not necessary to decide whether you need to modify the issue 
header content
-          IS_MODIFY_TITLE: false
-          CUSTOM_BOT_NOTE: RoBot detected the issue body's language is not 
English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ
+          script: |
+            const isComment = context.eventName === 'issue_comment';
+            const text = isComment
+              ? context.payload.comment.body
+              : context.payload.issue.body;
+
+            if (!text || !text.trim()) return;
+
+            // Skip bot users and our own translation comments
+            const actor = isComment ? context.payload.comment.user : 
context.payload.issue.user;
+            if (actor.type === 'Bot') return;
+            if (text.startsWith('> Bot detected the issue body')) return;
+
+            // Quick heuristic: low non-ASCII ratio means likely English
+            const nonAscii = (text.match(/[^\x00-\x7F]/g) || []).length;
+            if (nonAscii / text.length < 0.1) return;
+
+            // Detect source language from Unicode character ranges
+            const cjk = (text.match(/[\u4e00-\u9fff]/g) || []).length;
+            const kana = (text.match(/[\u3040-\u30ff]/g) || []).length;
+            const hangul = (text.match(/[\uac00-\ud7af]/g) || []).length;
+            const cyrillic = (text.match(/[\u0400-\u04ff]/g) || []).length;
+
+            let srcLang = 'zh-CN';
+            if (kana > cjk * 0.1) srcLang = 'ja';
+            else if (hangul > cjk) srcLang = 'ko';
+            else if (cyrillic > cjk) srcLang = 'ru';
+
+            // Split text into chunks (MyMemory limit: 500 chars/request)
+            const input = text.substring(0, 3000);
+            const chunks = [];
+            let remaining = input;
+            while (remaining.length > 0) {
+              if (remaining.length <= 500) {
+                chunks.push(remaining);
+                break;
+              }
+              let i = remaining.lastIndexOf('\n', 500);
+              if (i < 150) i = remaining.lastIndexOf('。', 500);
+              if (i < 150) i = remaining.lastIndexOf('. ', 500);
+              if (i < 0 || i < 150) i = 500;
+              else i++;
+              chunks.push(remaining.substring(0, i));
+              remaining = remaining.substring(i);
+            }
+
+            // Translate each chunk via MyMemory API (free, no key needed)
+            const translated = [];
+            for (const chunk of chunks) {
+              const params = new URLSearchParams({
+                q: chunk,
+                langpair: `${srcLang}|en`,
+              });
+              const res = await 
fetch('https://api.mymemory.translated.net/get', {
+                method: 'POST',
+                headers: { 'Content-Type': 'application/x-www-form-urlencoded' 
},
+                body: params.toString(),
+              });

Review Comment:
   The workflow sends the full issue/comment text to a third-party service 
(api.mymemory.translated.net) for translation. This can unintentionally 
exfiltrate sensitive information that users sometimes paste into issues 
(tokens, logs with secrets, emails). Consider gating translation behind an 
opt-in label/command, redacting common secret patterns before sending, and/or 
switching to an approved translation backend that keeps data within your 
control.



##########
.github/workflows/issue-robot.yml:
##########
@@ -22,12 +22,94 @@ on:
   issues:
     types: [opened]
 
+permissions:
+  issues: write
+
 jobs:
-  build:
+  translate:
     runs-on: ubuntu-latest
     steps:
-      - uses: tomsun28/[email protected]
+      - uses: actions/github-script@v7
         with:
-          # it is not necessary to decide whether you need to modify the issue 
header content
-          IS_MODIFY_TITLE: false
-          CUSTOM_BOT_NOTE: RoBot detected the issue body's language is not 
English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ
+          script: |
+            const isComment = context.eventName === 'issue_comment';
+            const text = isComment
+              ? context.payload.comment.body
+              : context.payload.issue.body;
+
+            if (!text || !text.trim()) return;
+
+            // Skip bot users and our own translation comments
+            const actor = isComment ? context.payload.comment.user : 
context.payload.issue.user;
+            if (actor.type === 'Bot') return;
+            if (text.startsWith('> Bot detected the issue body')) return;
+
+            // Quick heuristic: low non-ASCII ratio means likely English
+            const nonAscii = (text.match(/[^\x00-\x7F]/g) || []).length;
+            if (nonAscii / text.length < 0.1) return;
+
+            // Detect source language from Unicode character ranges
+            const cjk = (text.match(/[\u4e00-\u9fff]/g) || []).length;
+            const kana = (text.match(/[\u3040-\u30ff]/g) || []).length;
+            const hangul = (text.match(/[\uac00-\ud7af]/g) || []).length;
+            const cyrillic = (text.match(/[\u0400-\u04ff]/g) || []).length;
+

Review Comment:
   The non-ASCII heuristic counts emoji and other symbols as non-ASCII. An 
otherwise-English issue/comment with a moderate number of emoji or non-ASCII 
punctuation can exceed the 0.1 threshold and trigger an unnecessary translation 
comment. Consider excluding common emoji ranges / variation selectors from the 
count, or using a more robust language detection approach.
   ```suggestion
               // Quick heuristic: count only language-bearing non-English 
scripts,
               // not emoji, variation selectors, or other non-ASCII symbols.
               const cjkRegex = /[\u4e00-\u9fff]/g;
               const kanaRegex = /[\u3040-\u30ff]/g;
               const hangulRegex = /[\uac00-\ud7af]/g;
               const cyrillicRegex = /[\u0400-\u04ff]/g;
   
               const cjk = (text.match(cjkRegex) || []).length;
               const kana = (text.match(kanaRegex) || []).length;
               const hangul = (text.match(hangulRegex) || []).length;
               const cyrillic = (text.match(cyrillicRegex) || []).length;
               const meaningfulNonEnglish = cjk + kana + hangul + cyrillic;
               if (meaningfulNonEnglish / text.length < 0.1) return;
   
               // Detect source language from Unicode character ranges
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to