Skip to content

Mistake Notifier

Mistake Notifier #189

name: Mistake Notifier
on:
workflow_run:
workflows: [Mistake Checker]
types:
- completed
jobs:
notify:
name: Notify of mistakes
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
steps:
- name: Download mistake checker results
uses: actions/[email protected]
with:
script: |
let allArtifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "mistakes"
})[0];
let download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip
- name: Output detected mistakes if any
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let fs = require('fs');
const pr_number = Number(fs.readFileSync('./number.txt'));
const mistakes = JSON.parse(fs.readFileSync('./mistakes.txt').toString());
let message = '';
if (mistakes.length !== 0) {
message += 'Thank you for contributing!\n\n';
message += 'To keep translations error-free, we check them for mistakes. The files you changed seem to contain some, no worries though, they can be fixed! ';
message += `See helpful info below:\n\`\`\`diff\n`;
message += '===================================================================\n';
for (mistake of mistakes) {
message += `@@ Line: ${mistake.line} @@\n`;
switch (mistake.condition) {
case 'invalid_format':
message += '--- Non-Matching use of %s\n';
message += `+ msgid "${mistake.id}"\n`;
message += `- msgstr "${mistake.str}"\n`;
break;
case 'invalid_colors':
message += '!!! Possible misuse of colors\n';
message += `+ msgid "${mistake.id}"\n`;
message += `- msgstr "${mistake.str}"\n`;
break;
case 'invalid_colors_and_format':
message += '!!! Possible misuse of colors and format\n';
message += `+ msgid "${mistake.id}"\n`;
message += `- msgstr "${mistake.str}"\n`;
break;
}
if (mistakes.indexOf(mistake) !== mistakes.length - 1) {
message += '***************\n';
}
}
message += `===================================================================\n\`\`\``;
}
if (message !== "") {
github.rest.issues.createComment({
issue_number: pr_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
}