Skip to content

Commit c33b500

Browse files
committed
Create labels-cleanup.yml
1 parent a709975 commit c33b500

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Replace c- labels with case label
2+
3+
on:
4+
workflow_dispatch: # Manual trigger
5+
schedule:
6+
- cron: '0 0 * * 0' # Weekly on Sunday at midnight UTC
7+
8+
jobs:
9+
cleanup-labels:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: write
13+
14+
steps:
15+
- name: Replace c- labels with case label
16+
uses: actions/github-script@v7
17+
with:
18+
script: |
19+
const { owner, repo } = context.repo;
20+
21+
// Get all open issues
22+
const issues = await github.paginate(github.rest.issues.listForRepo, {
23+
owner,
24+
repo,
25+
state: 'open',
26+
per_page: 100
27+
});
28+
29+
console.log(`Found ${issues.length} open issues`);
30+
31+
let processedCount = 0;
32+
33+
for (const issue of issues) {
34+
// Skip pull requests
35+
if (issue.pull_request) continue;
36+
37+
// Find labels starting with "c-"
38+
const cLabels = issue.labels.filter(label =>
39+
typeof label === 'string'
40+
? label.startsWith('c-')
41+
: label.name.startsWith('c-')
42+
);
43+
44+
if (cLabels.length > 0) {
45+
console.log(`Issue #${issue.number}: Found ${cLabels.length} label(s) starting with c-`);
46+
47+
// Get label names
48+
const cLabelNames = cLabels.map(label =>
49+
typeof label === 'string' ? label : label.name
50+
);
51+
52+
// Get current labels that don't start with 'c-'
53+
const remainingLabels = issue.labels
54+
.filter(label => {
55+
const name = typeof label === 'string' ? label : label.name;
56+
return !name.startsWith('c-');
57+
})
58+
.map(label => typeof label === 'string' ? label : label.name);
59+
60+
// Add 'case' label if not already present
61+
if (!remainingLabels.includes('case')) {
62+
remainingLabels.push('case');
63+
}
64+
65+
// Update labels
66+
await github.rest.issues.setLabels({
67+
owner,
68+
repo,
69+
issue_number: issue.number,
70+
labels: remainingLabels
71+
});
72+
73+
console.log(`Issue #${issue.number}: Removed [${cLabelNames.join(', ')}], added 'case'`);
74+
processedCount++;
75+
}
76+
}
77+
78+
console.log(`\nProcessed ${processedCount} issue(s) with c- labels`);

0 commit comments

Comments
 (0)