-
Notifications
You must be signed in to change notification settings - Fork 1
62 lines (55 loc) · 2.05 KB
/
sync-and-del.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Sync + Delete GitHub Labels
on:
workflow_dispatch:
jobs:
sync-labels:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Sync labels from source to target repository
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const sourceRepo = 'StephanAkkerman/fintwit-bot';
const targetOwner = context.repo.owner;
const targetRepo = context.repo.repo;
// Fetch all labels from the target repository and delete them
const existingLabels = await github.rest.issues.listLabelsForRepo({
owner: targetOwner,
repo: targetRepo,
});
for (const label of existingLabels.data) {
await github.rest.issues.deleteLabel({
owner: targetOwner,
repo: targetRepo,
name: label.name,
});
}
// Fetch labels from the source repository
const sourceLabels = await github.rest.issues.listLabelsForRepo({
owner: sourceRepo.split('/')[0],
repo: sourceRepo.split('/')[1],
});
// Create labels in the target repository using the source labels
for (const label of sourceLabels.data) {
await github.rest.issues.createLabel({
owner: targetOwner,
repo: targetRepo,
name: label.name,
color: label.color,
description: label.description || '',
}).catch(error => {
if (error.status === 422) {
await github.rest.issues.updateLabel({
owner: targetOwner,
repo: targetRepo,
current_name: label.name,
name: label.name,
color: label.color,
description: label.description || '',
});
}
});
}