1616 if : ${{ github.repository_owner == 'AOSSIE-Org' }}
1717 runs-on : ubuntu-latest
1818 steps :
19+ # STEP 0: Ensure all labels exist with correct colors
20+ - name : Upsert colored labels
21+ uses : actions/github-script@v7
22+ with :
23+ github-token : ${{ secrets.GITHUB_TOKEN }}
24+ script : |
25+ const labels = [
26+ { name: 'documentation', color: '0075ca', description: 'Documentation updates' },
27+ { name: 'enhancement', color: 'a2eeef', description: 'New feature or request' },
28+ { name: 'frontend', color: '7057ff', description: 'Frontend changes' },
29+ { name: 'javascript', color: 'f0e040', description: 'JavaScript/TypeScript changes' },
30+ { name: 'dependencies', color: 'e4e669', description: 'Dependency updates' },
31+ { name: 'configuration', color: 'f9d0c4', description: 'Config file changes' },
32+ { name: 'good first issue', color: '7cfc00', description: 'Good for newcomers' },
33+ { name: 'first-time-contributor', color: 'ff9500', description: 'First time contributor' },
34+ { name: 'no-issue-linked', color: 'd93f0b', description: 'PR has no linked issue' },
35+ { name: 'size/XS', color: '3cbf00', description: '1-10 lines changed' },
36+ { name: 'size/S', color: '5d9801', description: '11-50 lines changed' },
37+ { name: 'size/M', color: 'ffd700', description: '51-200 lines changed' },
38+ { name: 'size/L', color: 'ff8c00', description: '201-500 lines changed' },
39+ { name: 'size/XL', color: 'e11d48', description: '500+ lines changed' },
40+ { name: 'ci-cd', color: '00c0ef', description: 'CI/CD changes' },
41+ { name: 'github-actions', color: '0052cc', description: 'GitHub Actions changes' },
42+ { name: 'backend', color: 'c5def5', description: 'Backend changes' },
43+ { name: 'python', color: 'ffe066', description: 'Python changes' },
44+ { name: 'tests', color: 'bfd4f2', description: 'Test changes' },
45+ { name: 'docker', color: '0db7ed', description: 'Docker changes' },
46+ { name: 'member', color: '006b75', description: 'Org member' },
47+ { name: 'external-contributor', color: 'e6e6e6', description: 'External contributor' },
48+ { name: 'maintainer', color: 'b60205', description: 'Maintainer' },
49+ ];
50+ for (const label of labels) {
51+ try {
52+ await github.rest.issues.updateLabel({
53+ owner: context.repo.owner,
54+ repo: context.repo.repo,
55+ name: label.name,
56+ color: label.color,
57+ description: label.description
58+ });
59+ } catch (e) {
60+ if (e.status === 404) {
61+ await github.rest.issues.createLabel({
62+ owner: context.repo.owner,
63+ repo: context.repo.repo,
64+ name: label.name,
65+ color: label.color,
66+ description: label.description
67+ });
68+ } else {
69+ throw e;
70+ }
71+ }
72+ }
73+
74+ # STEP 1: Issue-based labels
1975 - name : Get PR details
2076 id : pr-details
2177 uses : actions/github-script@v7
3086 head: pr.head.ref
3187 };
3288
33- # STEP 1: Issue-based labels
3489 - name : Extract linked issue number
3590 id : extract-issue
3691 uses : actions/github-script@v7
68123 const prNumber = context.payload.pull_request.number;
69124
70125 try {
71- // Fetch issue labels
72126 const issue = await github.rest.issues.get({
73127 owner: context.repo.owner,
74128 repo: context.repo.repo,
81135
82136 if (issueLabels.length > 0) {
83137 console.log(`Applying issue-based labels: ${issueLabels.join(', ')}`);
84-
85- // Add labels from issue
86138 await github.rest.issues.addLabels({
87139 owner: context.repo.owner,
88140 repo: context.repo.repo,
@@ -101,10 +153,7 @@ jobs:
101153 github-token : ${{ secrets.GITHUB_TOKEN }}
102154 script : |
103155 const prNumber = context.payload.pull_request.number;
104-
105156 console.log('No issue linked to this PR');
106-
107- // Add "no-issue-linked" label
108157 await github.rest.issues.addLabels({
109158 owner: context.repo.owner,
110159 repo: context.repo.repo,
@@ -120,17 +169,13 @@ jobs:
120169 github-token : ${{ secrets.GITHUB_TOKEN }}
121170 script : |
122171 const prNumber = context.payload.pull_request.number;
123-
124- // Get list of files changed in the PR
125172 const files = await github.rest.pulls.listFiles({
126173 owner: context.repo.owner,
127174 repo: context.repo.repo,
128175 pull_number: prNumber
129176 });
130-
131177 const changedFiles = files.data.map(file => file.filename);
132178 core.setOutput('files', JSON.stringify(changedFiles));
133-
134179 return changedFiles;
135180
136181 - name : Apply file-based labels
@@ -142,8 +187,6 @@ jobs:
142187 const changedFiles = JSON.parse('${{ steps.changed-files.outputs.files }}');
143188
144189 const fileLabels = [];
145-
146- // Define file-based label mappings
147190 const labelMappings = {
148191 'documentation': ['.md', 'README', 'CONTRIBUTING', 'LICENSE', '.txt'],
149192 'frontend': ['.html', '.css', '.scss', '.jsx', '.tsx', '.vue'],
@@ -158,7 +201,6 @@ jobs:
158201 'ci-cd': ['.github/', '.gitlab-ci', 'Jenkinsfile', '.circleci']
159202 };
160203
161- // Check each file against label mappings
162204 for (const file of changedFiles) {
163205 for (const [label, patterns] of Object.entries(labelMappings)) {
164206 for (const pattern of patterns) {
@@ -173,7 +215,6 @@ jobs:
173215
174216 if (fileLabels.length > 0) {
175217 console.log(`Applying file-based labels: ${fileLabels.join(', ')}`);
176-
177218 await github.rest.issues.addLabels({
178219 owner: context.repo.owner,
179220 repo: context.repo.repo,
@@ -191,8 +232,6 @@ jobs:
191232 github-token : ${{ secrets.GITHUB_TOKEN }}
192233 script : |
193234 const prNumber = context.payload.pull_request.number;
194-
195- // Get PR details to calculate size
196235 const pr = await github.rest.pulls.get({
197236 owner: context.repo.owner,
198237 repo: context.repo.repo,
@@ -202,10 +241,8 @@ jobs:
202241 const additions = pr.data.additions;
203242 const deletions = pr.data.deletions;
204243 const totalChanges = additions + deletions;
205-
206244 console.log(`PR has ${additions} additions and ${deletions} deletions (${totalChanges} total changes)`);
207245
208- // Determine size label based on total changes
209246 let sizeLabel = '';
210247 if (totalChanges <= 10) {
211248 sizeLabel = 'size/XS';
@@ -221,7 +258,6 @@ jobs:
221258
222259 console.log(`Applying size label: ${sizeLabel}`);
223260
224- // Remove any existing size labels first
225261 const currentLabels = await github.rest.issues.listLabelsOnIssue({
226262 owner: context.repo.owner,
227263 repo: context.repo.repo,
@@ -241,7 +277,6 @@ jobs:
241277 });
242278 }
243279
244- // Apply the new size label
245280 await github.rest.issues.addLabels({
246281 owner: context.repo.owner,
247282 repo: context.repo.repo,
@@ -261,7 +296,6 @@ jobs:
261296 const prAuthor = context.payload.pull_request.user.login;
262297
263298 try {
264- // Check if user is a first-time contributor
265299 const commits = await github.rest.repos.listCommits({
266300 owner: context.repo.owner,
267301 repo: context.repo.repo,
@@ -270,30 +304,26 @@ jobs:
270304
271305 const contributorLabels = [];
272306
273- // Check if contributor is a member of the organization
274307 try {
275308 await github.rest.orgs.checkMembershipForUser({
276309 org: context.repo.owner,
277310 username: prAuthor
278311 });
279312 contributorLabels.push('member');
280313 } catch (error) {
281- // Not a member
282314 if (commits.data.length <= 1) {
283315 contributorLabels.push('first-time-contributor');
284316 } else {
285317 contributorLabels.push('external-contributor');
286318 }
287319 }
288320
289- // Check if PR author is a collaborator
290321 try {
291322 const permissionLevel = await github.rest.repos.getCollaboratorPermissionLevel({
292323 owner: context.repo.owner,
293324 repo: context.repo.repo,
294325 username: prAuthor
295326 });
296-
297327 if (permissionLevel.data.permission === 'admin' || permissionLevel.data.permission === 'maintain') {
298328 contributorLabels.push('maintainer');
299329 }
@@ -303,7 +333,6 @@ jobs:
303333
304334 if (contributorLabels.length > 0) {
305335 console.log(`Applying contributor-based labels: ${contributorLabels.join(', ')}`);
306-
307336 await github.rest.issues.addLabels({
308337 owner: context.repo.owner,
309338 repo: context.repo.repo,
@@ -322,18 +351,15 @@ jobs:
322351 github-token : ${{ secrets.GITHUB_TOKEN }}
323352 script : |
324353 const prNumber = context.payload.pull_request.number;
325-
326- // Get current labels on PR
327354 const pr = await github.rest.issues.get({
328355 owner: context.repo.owner,
329356 repo: context.repo.repo,
330357 issue_number: prNumber
331358 });
332-
333359 const currentLabels = pr.data.labels.map(label => label.name);
334360 console.log('='.repeat(50));
335361 console.log('PR Label Sync Complete');
336362 console.log('='.repeat(50));
337363 console.log(`Current labels on PR #${prNumber}:`);
338364 console.log(currentLabels.join(', ') || 'No labels');
339- console.log('='.repeat(50));
365+ console.log('='.repeat(50));
0 commit comments