|
16 | 16 | jobs: |
17 | 17 | translate: |
18 | 18 | permissions: |
| 19 | + contents: read |
19 | 20 | issues: write |
20 | 21 | discussions: write |
21 | 22 | pull-requests: write |
22 | 23 | runs-on: ubuntu-latest |
23 | 24 | steps: |
24 | | - - uses: lizheming/github-translate-action@1.1.2 |
| 25 | + - uses: actions/checkout@v3 |
| 26 | + - name: Check if content contains Chinese |
| 27 | + id: check-chinese |
| 28 | + if: github.event_name == 'issues' |
| 29 | + uses: actions/github-script@v7 |
| 30 | + with: |
| 31 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + script: | |
| 33 | + let content = ''; |
| 34 | + let hasChinese = false; |
| 35 | + if (context.payload.issue) { |
| 36 | + content = (context.payload.issue.title || '') + ' ' + (context.payload.issue.body || ''); |
| 37 | + } |
| 38 | + console.log('Content:', content); |
| 39 | +
|
| 40 | + const chineseRegex = /[\u4e00-\u9fff]/; |
| 41 | + hasChinese = chineseRegex.test(content); |
| 42 | + console.log('Chinese?:', hasChinese); |
| 43 | +
|
| 44 | + core.setOutput('hasChinese', hasChinese ? 'true' : 'false'); |
| 45 | + - name: Translate content |
| 46 | + uses: oceanbase/github-translate-action@ob-1.1.2 |
25 | 47 | env: |
26 | 48 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
27 | 49 | with: |
28 | 50 | IS_MODIFY_TITLE: true |
29 | | - APPEND_TRANSLATION: false |
| 51 | + APPEND_TRANSLATION: true |
| 52 | + - name: Add comment to issue or pull request |
| 53 | + if: github.event_name == 'issues' && steps.check-chinese.outputs.hasChinese == 'true' |
| 54 | + uses: actions/github-script@v7 |
| 55 | + with: |
| 56 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + script: | |
| 58 | + const issueNumber = context.issue.number; |
| 59 | +
|
| 60 | + github.rest.issues.createComment({ |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + issue_number: issueNumber, |
| 64 | + body: 'Please ask your question at https://ask.oceanbase.com/' |
| 65 | + }); |
0 commit comments