Skip to content

Commit 0d7bd2b

Browse files
committed
feat: refine translation prompt and remove checkout step in issue translation workflow
1 parent d6140bd commit 0d7bd2b

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

.github/workflows/issue-translation.yml

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,18 @@ jobs:
2727
issues: write
2828
id-token: write
2929
steps:
30-
- name: Checkout repository
31-
uses: actions/checkout@v4
32-
with:
33-
fetch-depth: 0
34-
3530
- name: Translate issue body with Claude (auto detect)
3631
id: translate
3732
uses: anthropics/claude-code-action@v1
3833
with:
3934
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
40-
github_token: ${{ secrets.GITHUB_TOKEN }}
4135
prompt: |
42-
你是一个专业的翻译助手。请翻译以下 GitHub issue 的内容。
43-
44-
IMPORTANT: 只更新 issue 内容,不要创建 pull request 或分支。
45-
46-
任务:
47-
1. 使用 mcp__github__get_issue 获取 issue 详情
48-
2. 检测 issue 标题和内容的语言
49-
3. 如果是中文,翻译成英文;如果是英文,翻译成中文
50-
4. 不要解释,不要输出原文,只返回翻译内容。
51-
52-
Issue 信息:
53-
- REPO: ${{ github.repository }}
54-
- ISSUE_NUMBER: ${{ github.event.issue.number }}
55-
56-
翻译格式:
57-
---
58-
**Translation / 翻译**
59-
[翻译内容]
36+
你是一名专业的双语翻译。请自动检测下面文本的主要语言(只会是中文或英文):
37+
- 如果主要语言是中文,请将其准确、地道地翻译为英文,只返回英文翻译。
38+
- 如果主要语言是英文,请将其准确、地道地翻译为中文,只返回中文翻译。
39+
- 不要解释,不要输出原文,只返回翻译内容。
6040
---
61-
{{ issue.body }}
62-
env:
63-
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
64-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
${{ github.event.issue.body }}
6542
6643
- name: Update issue body with original and translation
6744
uses: actions/github-script@v7
@@ -72,11 +49,22 @@ jobs:
7249
const owner = context.repo.owner;
7350
const repo = context.repo.repo;
7451
const orig = context.payload.issue.body || '';
75-
const translated = `${{ steps.translate.outputs.result }}`.trim();
76-
const newBody = `## 原文\n${orig}\n\n## 翻译\n${translated}`;
77-
await github.rest.issues.update({
78-
owner,
79-
repo,
80-
issue_number,
81-
body: newBody,
82-
});
52+
53+
// Get the translation from the previous step
54+
// Note: The exact output property may vary, trying common ones
55+
const stepOutputs = ${{ toJson(steps.translate.outputs) }};
56+
const translated = (stepOutputs.response || stepOutputs.result || stepOutputs.output || '').trim();
57+
58+
// Only update if we have a translation and it's different from original
59+
if (translated && translated !== orig && translated !== 'undefined') {
60+
const newBody = `## 原文 / Original\n${orig}\n\n## 翻译 / Translation\n${translated}`;
61+
await github.rest.issues.update({
62+
owner,
63+
repo,
64+
issue_number,
65+
body: newBody,
66+
});
67+
console.log('Successfully updated issue with translation');
68+
} else {
69+
console.log('No valid translation received or translation same as original');
70+
}

0 commit comments

Comments
 (0)