1- name : Label Issues
1+ name : Label Issues and PRs
22
33on :
44 issues :
55 types :
66 - opened
77 - transferred
8+ pull_request :
9+ types :
10+ - opened
811
912permissions :
1013 issues : write
14+ pull-requests : write
1115
1216jobs :
1317 label-issue :
@@ -17,58 +21,75 @@ jobs:
1721 uses : actions/github-script@v7
1822 with :
1923 script : |
20- // Define the mapping from repo/template value to label
2124 const labelMap = {
2225 'supabase/auth-js': 'auth-js',
2326 'supabase/functions-js': 'functions-js',
2427 'supabase/postgrest-js': 'postgrest-js',
2528 'supabase/storage-js': 'storage-js',
2629 'supabase/realtime-js': 'realtime-js',
30+ 'supabase/supabase-js': 'supabase-js',
2731 'auth-js': 'auth-js',
2832 'functions-js': 'functions-js',
2933 'postgrest-js': 'postgrest-js',
3034 'storage-js': 'storage-js',
3135 'realtime-js': 'realtime-js',
36+ 'supabase-js': 'supabase-js',
37+ };
38+
39+ const scopeToLabel = {
40+ 'auth': 'auth-js',
41+ 'functions': 'functions-js',
42+ 'postgrest': 'postgrest-js',
43+ 'storage': 'storage-js',
44+ 'realtime': 'realtime-js',
45+ 'supabase': 'supabase-js',
3246 };
3347
3448 let labels = [];
49+ const isPR = !!context.payload.pull_request;
50+ const item = context.payload.pull_request || context.payload.issue;
51+ const itemNumber = item.number;
3552
36- const oldRepoFullName = context.payload.changes?.old_repository?.full_name;
37- if (oldRepoFullName) {
38- const fullNameLower = (oldRepoFullName || '').toLowerCase();
39- const shortName = fullNameLower.split('/')?.[1];
40- console.log('old_repository', fullNameLower, shortName);
41- const transferLabel = labelMap[fullNameLower] || labelMap[shortName];
42- if (transferLabel) labels.push(transferLabel);
43- } else {
44- // Label based on "Library affected" field in the issue body
45- const body = context.payload.issue.body || '';
46- const match = body.match(/### Library affected\s*\n+([\s\S]*?)(\n###|\n$)/i);
47- if (match) {
48- const libsRaw = match[1];
49- // Split by comma, semicolon, or newlines
50- const libs = libsRaw.split(/,|;|\n/).map(s => s.trim().toLowerCase()).filter(Boolean);
51- for (const lib of libs) {
52- if (labelMap[lib]) labels.push(labelMap[lib]);
53+ if (isPR) {
54+ const title = item.title || '';
55+ const scopeMatch = title.match(/^[a-z]+\(([a-z]+)\):/);
56+ if (scopeMatch) {
57+ const scope = scopeMatch[1];
58+ if (scopeToLabel[scope]) {
59+ labels.push(scopeToLabel[scope]);
5360 }
5461 }
55- // Check the title for "[migration]"
56- const title = context.payload.issue.title || '';
57- if (title.toLowerCase().includes('[migration]')) {
58- labels.push('migration');
62+ } else {
63+ const oldRepoFullName = context.payload.changes?.old_repository?.full_name;
64+ if (oldRepoFullName) {
65+ const fullNameLower = (oldRepoFullName || '').toLowerCase();
66+ const shortName = fullNameLower.split('/')?.[1];
67+ const transferLabel = labelMap[fullNameLower] || labelMap[shortName];
68+ if (transferLabel) labels.push(transferLabel);
69+ } else {
70+ const body = item.body || '';
71+ const match = body.match(/### Library affected\s*\n+([\s\S]*?)(\n###|\n$)/i);
72+ if (match) {
73+ const libsRaw = match[1];
74+ const libs = libsRaw.split(/,|;|\n/).map(s => s.trim().toLowerCase()).filter(Boolean);
75+ for (const lib of libs) {
76+ if (labelMap[lib]) labels.push(labelMap[lib]);
77+ }
78+ }
79+ const title = item.title || '';
80+ if (title.toLowerCase().includes('[migration]')) {
81+ labels.push('migration');
82+ }
5983 }
6084 }
6185
62- // Remove duplicates
6386 labels = [...new Set(labels)];
6487
6588 if (labels.length > 0) {
6689 await github.rest.issues.addLabels({
6790 owner: context.repo.owner,
6891 repo: context.repo.repo,
69- issue_number: context.payload.issue.number ,
92+ issue_number: itemNumber ,
7093 labels,
7194 });
72- } else {
73- console.log('No matching label found; no label added.');
7495 }
0 commit comments