Skip to content

Commit 58e97ca

Browse files
committed
Added unique maintainer tagging
Signed-off-by: Ujwal Akotkar <24bcs012@iiitdwd.ac.in>
1 parent f66491a commit 58e97ca

File tree

1 file changed

+68
-14
lines changed

1 file changed

+68
-14
lines changed

.github/workflows/translation-check.yml

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ on:
99
permissions:
1010
contents: read
1111
pull-requests: write
12+
issues: read
1213

1314
jobs:
1415
notify:
1516
runs-on: ubuntu-latest
17+
1618
steps:
1719
- name: Checkout repository
1820
uses: actions/checkout@v4
@@ -57,7 +59,7 @@ jobs:
5759
id: issue
5860
uses: actions/github-script@v7
5961
env:
60-
ISSUE_NUMBER: "488" # <- change if your canonical issue is different
62+
ISSUE_NUMBER: "488" # Replace with your issue number
6163
with:
6264
script: |
6365
const issue_number = Number(process.env.ISSUE_NUMBER);
@@ -68,43 +70,95 @@ jobs:
6870
});
6971
core.setOutput('body', data.body || '');
7072
71-
- name: Extract @handles from issue description
72-
id: handles
73+
- name: Map languages to maintainers (Dynamic)
74+
id: mapping
7375
uses: actions/github-script@v7
76+
env:
77+
LANGUAGES: ${{ steps.txt.outputs.list }}
78+
ISSUE_BODY: ${{ steps.issue.outputs.body }}
7479
with:
7580
script: |
76-
// Basic: all @mentions in the issue body
77-
const body = `${{ steps.issue.outputs.body }}`;
78-
const tags = [...new Set((body.match(/@\w[\w-]+/g) || []))];
79-
core.setOutput('handles', tags.join(' '));
81+
const body = process.env.ISSUE_BODY || '';
82+
const langJson = process.env.LANGUAGES || '{}';
83+
84+
// Parse JSON keys from untranslated.txt
85+
let untranslatedKeys = [];
86+
try {
87+
const parsed = JSON.parse(langJson);
88+
untranslatedKeys = Object.keys(parsed).map(k => k.toLowerCase());
89+
} catch(e) {
90+
console.log("Failed to parse untranslated.txt JSON, fallback to lines");
91+
untranslatedKeys = langJson.split(/\r?\n/).map(l => l.trim().toLowerCase()).filter(Boolean);
92+
}
93+
94+
const langToHandles = {};
95+
96+
// Parse "- Language by @user" or table rows "| Language | @user |"
97+
const listRegex = /([\w\s]+)\s+by\s+(.+)/gi;
98+
const tableRegex = /\|\s*([\w\s]+)\s*\|\s*(.+)\s*\|/gi;
99+
100+
let match;
101+
while ((match = listRegex.exec(body)) !== null) {
102+
const lang = match[1].trim().toLowerCase();
103+
const handles = match[2].trim().split(/\s+/);
104+
langToHandles[lang] = handles;
105+
langToHandles[lang.slice(0,2)] = handles; // map 2-letter code
106+
}
107+
108+
while ((match = tableRegex.exec(body)) !== null) {
109+
const lang = match[1].trim().toLowerCase();
110+
const handles = match[2].trim().split(/\s+/);
111+
langToHandles[lang] = handles;
112+
langToHandles[lang.slice(0,2)] = handles; // map 2-letter code
113+
}
114+
115+
// Build output mapping of language -> handles
116+
const output = [];
117+
for (const code of untranslatedKeys) {
118+
const handles = langToHandles[code];
119+
if (handles) {
120+
const langName = Object.keys(langToHandles).find(k => k.slice(0,2)===code) || code;
121+
output.push(`${langName}: ${handles.join(' ')}`);
122+
}
123+
}
124+
125+
core.setOutput('handles', output.join('\n'));
80126
81127
- name: Build PR comment body
82128
id: comment
83129
run: |
84130
{
85131
echo 'body<<EOF'
86-
echo '🔔 Translation check'
132+
echo '🔔 **Translation Check Notice**'
87133
echo
88-
echo 'The following keys/files are listed in lib/i18n/untranslated.txt:'
134+
echo 'The following untranslated language codes were found in `untranslated.txt`:'
89135
if [ -n "${{ steps.txt.outputs.list }}" ]; then
136+
echo '```'
90137
echo "${{ steps.txt.outputs.list }}"
138+
echo '```'
91139
else
92140
echo '- No entries found'
93141
fi
94142
echo
95-
echo "Notifying: ${{ steps.handles.outputs.handles }}"
143+
echo "📣 Notifying maintainers per language:"
144+
echo "${{ steps.mapping.outputs.handles }}"
96145
echo
97-
echo '_Automated post-merge notice_'
146+
echo '_Automated post-merge notice by Translation Notifier_'
98147
echo 'EOF'
99148
} >> $GITHUB_OUTPUT
100149
101150
- name: Post comment to merged PR
102151
uses: actions/github-script@v7
152+
env:
153+
PR_NUMBER: ${{ steps.pr.outputs.number }}
154+
COMMENT_BODY: ${{ steps.comment.outputs.body }}
103155
with:
104156
script: |
157+
const issueNumber = Number(process.env.PR_NUMBER || 1);
158+
const body = process.env.COMMENT_BODY || 'No comment generated.';
105159
await github.rest.issues.createComment({
106160
owner: context.repo.owner,
107161
repo: context.repo.repo,
108-
issue_number: Number('${{ steps.pr.outputs.number }}'),
109-
body: `${{ steps.comment.outputs.body }}`
110-
});
162+
issue_number: issueNumber,
163+
body
164+
});

0 commit comments

Comments
 (0)