-
Notifications
You must be signed in to change notification settings - Fork 69
97 lines (82 loc) · 3.44 KB
/
mistake_notifier.yml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
});
}