-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically post a warning comment when translation files are changed
- Loading branch information
Showing
3 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: Detect translation file changes | ||
|
||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- lang/po/*.po | ||
- lang/po/*.pot | ||
|
||
|
||
jobs: | ||
po-change-warning: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Detect translation file changes" | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const skip_phrase = 'Translation file changes are intended'; | ||
if (context.payload.pull_request.body.includes(skip_phrase)) { | ||
console.log('PR body contains skip phrase. Exiting.'); | ||
return; | ||
} | ||
core.setFailed('Translation file changes detected, but a skip phrase is not found in the PR body.') | ||
console.log( | ||
'Fetching comments of pull request %d of repository %s/%s.', | ||
context.issue.number, context.repo.owner, context.repo.repo | ||
); | ||
const comments = await github.paginate( | ||
github.rest.issues.listComments, | ||
{ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number | ||
} | ||
); | ||
const body = 'It appears you modified a `.po` or `.pot` file. ' | ||
+ 'These translation files are automatically generated, ' | ||
+ 'pushed to, and pulled from Transifex, and should not be ' | ||
+ 'modified otherwise. If these changes are intended, please ' | ||
+ 'add `' + skip_phrase + '` to the ' | ||
+ 'PR body.'; | ||
comments.reverse(); | ||
const bot_comments = comments.filter( | ||
comment => comment.user.type === 'Bot' | ||
&& comment.user.login === 'github-actions[bot]' | ||
&& comment.body === body | ||
); | ||
if (bot_comments.length > 0) { | ||
console.log('Comment already exists. Exiting.'); | ||
return; | ||
} | ||
console.log('Posting comment.'); | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: body | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters