-
Notifications
You must be signed in to change notification settings - Fork 4
75 lines (69 loc) · 3.01 KB
/
issue-translation.yml
File metadata and controls
75 lines (69 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright 2024-2026 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Bidirectional Issue Translation and Update
on:
issues:
types: [opened]
env:
ANTHROPIC_BASE_URL: "https://open.bigmodel.cn/api/anthropic"
jobs:
translate_and_update:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Translate issue body with Claude (auto detect)
id: translate
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: |
你是一名专业的双语翻译。请自动检测下面文本的主要语言(只会是中文或英文):
- 如果主要语言是中文,请将其准确、地道地翻译为英文,只返回英文翻译。
- 如果主要语言是英文,请将其准确、地道地翻译为中文,只返回中文翻译。
- 不要解释,不要输出原文,只返回翻译内容。
---
${{ github.event.issue.body }}
- name: Update issue body with original and translation
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const orig = context.payload.issue.body || '';
// Get the translation from the previous step
// Note: The exact output property may vary, trying common ones
const stepOutputs = ${{ toJson(steps.translate.outputs) }};
const translated = (stepOutputs.response || stepOutputs.result || stepOutputs.output || '').trim();
// Only update if we have a translation and it's different from original
if (translated && translated !== orig && translated !== 'undefined') {
const newBody = `## 原文 / Original\n${orig}\n\n## 翻译 / Translation\n${translated}`;
await github.rest.issues.update({
owner,
repo,
issue_number,
body: newBody,
});
console.log('Successfully updated issue with translation');
} else {
console.log('No valid translation received or translation same as original');
}