Skip to content

Commit

Permalink
Automatically post a warning comment when translation files are changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox committed Mar 7, 2022
1 parent 2c922b0 commit 165a6fb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/detect-translation-file-changes.yml
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:
detect-translation-file-changes:
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
});
8 changes: 6 additions & 2 deletions .github/workflows/post-spell-check-result.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ jobs:
}
);
comments.reverse();
const bot_comments = comments.filter(comment => comment.user.type === 'Bot' && comment.user.login === 'github-actions[bot]');
if (bot_comments.length > 0 && bot_comments[0].body === body) {
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;
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:
delete-branch: true
base: master
title: Routine i18n updates on ${{ steps.current-date.outputs.formattedTime }}
body: "#### Summary\nNone"
body: "#### Summary\nNone\n\n#### Additional context\n`Translation file changes are intended`"
labels: Translation

0 comments on commit 165a6fb

Please sign in to comment.