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+ await github.rest.issues.createLabel({
61+ owner: context.repo.owner,
62+ repo: context.repo.repo,
63+ name: label.name,
64+ color: label.color,
65+ description: label.description
66+ });
67+ }
68+ }
69+
70+ # STEP 1: Issue-based labels
1971 - name : Get PR details
2072 id : pr-details
2173 uses : actions/github-script@v7
3082 head: pr.head.ref
3183 };
3284
33- # STEP 1: Issue-based labels
3485 - name : Extract linked issue number
3586 id : extract-issue
3687 uses : actions/github-script@v7
68119 const prNumber = context.payload.pull_request.number;
69120
70121 try {
71- // Fetch issue labels
72122 const issue = await github.rest.issues.get({
73123 owner: context.repo.owner,
74124 repo: context.repo.repo,
81131
82132 if (issueLabels.length > 0) {
83133 console.log(`Applying issue-based labels: ${issueLabels.join(', ')}`);
84-
85- // Add labels from issue
86134 await github.rest.issues.addLabels({
87135 owner: context.repo.owner,
88136 repo: context.repo.repo,
@@ -101,10 +149,7 @@ jobs:
101149 github-token : ${{ secrets.GITHUB_TOKEN }}
102150 script : |
103151 const prNumber = context.payload.pull_request.number;
104-
105152 console.log('No issue linked to this PR');
106-
107- // Add "no-issue-linked" label
108153 await github.rest.issues.addLabels({
109154 owner: context.repo.owner,
110155 repo: context.repo.repo,
@@ -120,17 +165,13 @@ jobs:
120165 github-token : ${{ secrets.GITHUB_TOKEN }}
121166 script : |
122167 const prNumber = context.payload.pull_request.number;
123-
124- // Get list of files changed in the PR
125168 const files = await github.rest.pulls.listFiles({
126169 owner: context.repo.owner,
127170 repo: context.repo.repo,
128171 pull_number: prNumber
129172 });
130-
131173 const changedFiles = files.data.map(file => file.filename);
132174 core.setOutput('files', JSON.stringify(changedFiles));
133-
134175 return changedFiles;
135176
136177 - name : Apply file-based labels
@@ -142,8 +183,6 @@ jobs:
142183 const changedFiles = JSON.parse('${{ steps.changed-files.outputs.files }}');
143184
144185 const fileLabels = [];
145-
146- // Define file-based label mappings
147186 const labelMappings = {
148187 'documentation': ['.md', 'README', 'CONTRIBUTING', 'LICENSE', '.txt'],
149188 'frontend': ['.html', '.css', '.scss', '.jsx', '.tsx', '.vue'],
@@ -158,7 +197,6 @@ jobs:
158197 'ci-cd': ['.github/', '.gitlab-ci', 'Jenkinsfile', '.circleci']
159198 };
160199
161- // Check each file against label mappings
162200 for (const file of changedFiles) {
163201 for (const [label, patterns] of Object.entries(labelMappings)) {
164202 for (const pattern of patterns) {
@@ -173,7 +211,6 @@ jobs:
173211
174212 if (fileLabels.length > 0) {
175213 console.log(`Applying file-based labels: ${fileLabels.join(', ')}`);
176-
177214 await github.rest.issues.addLabels({
178215 owner: context.repo.owner,
179216 repo: context.repo.repo,
@@ -191,8 +228,6 @@ jobs:
191228 github-token : ${{ secrets.GITHUB_TOKEN }}
192229 script : |
193230 const prNumber = context.payload.pull_request.number;
194-
195- // Get PR details to calculate size
196231 const pr = await github.rest.pulls.get({
197232 owner: context.repo.owner,
198233 repo: context.repo.repo,
@@ -202,10 +237,8 @@ jobs:
202237 const additions = pr.data.additions;
203238 const deletions = pr.data.deletions;
204239 const totalChanges = additions + deletions;
205-
206240 console.log(`PR has ${additions} additions and ${deletions} deletions (${totalChanges} total changes)`);
207241
208- // Determine size label based on total changes
209242 let sizeLabel = '';
210243 if (totalChanges <= 10) {
211244 sizeLabel = 'size/XS';
@@ -221,7 +254,6 @@ jobs:
221254
222255 console.log(`Applying size label: ${sizeLabel}`);
223256
224- // Remove any existing size labels first
225257 const currentLabels = await github.rest.issues.listLabelsOnIssue({
226258 owner: context.repo.owner,
227259 repo: context.repo.repo,
@@ -241,7 +273,6 @@ jobs:
241273 });
242274 }
243275
244- // Apply the new size label
245276 await github.rest.issues.addLabels({
246277 owner: context.repo.owner,
247278 repo: context.repo.repo,
@@ -261,7 +292,6 @@ jobs:
261292 const prAuthor = context.payload.pull_request.user.login;
262293
263294 try {
264- // Check if user is a first-time contributor
265295 const commits = await github.rest.repos.listCommits({
266296 owner: context.repo.owner,
267297 repo: context.repo.repo,
@@ -270,30 +300,26 @@ jobs:
270300
271301 const contributorLabels = [];
272302
273- // Check if contributor is a member of the organization
274303 try {
275304 await github.rest.orgs.checkMembershipForUser({
276305 org: context.repo.owner,
277306 username: prAuthor
278307 });
279308 contributorLabels.push('member');
280309 } catch (error) {
281- // Not a member
282310 if (commits.data.length <= 1) {
283311 contributorLabels.push('first-time-contributor');
284312 } else {
285313 contributorLabels.push('external-contributor');
286314 }
287315 }
288316
289- // Check if PR author is a collaborator
290317 try {
291318 const permissionLevel = await github.rest.repos.getCollaboratorPermissionLevel({
292319 owner: context.repo.owner,
293320 repo: context.repo.repo,
294321 username: prAuthor
295322 });
296-
297323 if (permissionLevel.data.permission === 'admin' || permissionLevel.data.permission === 'maintain') {
298324 contributorLabels.push('maintainer');
299325 }
@@ -303,7 +329,6 @@ jobs:
303329
304330 if (contributorLabels.length > 0) {
305331 console.log(`Applying contributor-based labels: ${contributorLabels.join(', ')}`);
306-
307332 await github.rest.issues.addLabels({
308333 owner: context.repo.owner,
309334 repo: context.repo.repo,
@@ -322,18 +347,15 @@ jobs:
322347 github-token : ${{ secrets.GITHUB_TOKEN }}
323348 script : |
324349 const prNumber = context.payload.pull_request.number;
325-
326- // Get current labels on PR
327350 const pr = await github.rest.issues.get({
328351 owner: context.repo.owner,
329352 repo: context.repo.repo,
330353 issue_number: prNumber
331354 });
332-
333355 const currentLabels = pr.data.labels.map(label => label.name);
334356 console.log('='.repeat(50));
335357 console.log('PR Label Sync Complete');
336358 console.log('='.repeat(50));
337359 console.log(`Current labels on PR #${prNumber}:`);
338360 console.log(currentLabels.join(', ') || 'No labels');
339- console.log('='.repeat(50));
361+ console.log('='.repeat(50));
0 commit comments