-
Notifications
You must be signed in to change notification settings - Fork 137
80 lines (71 loc) · 3.37 KB
/
add-hacktoberfest-label.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Add Hacktoberfest Labels
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
add_labels:
runs-on: ubuntu-latest
env:
# Define labels as variables for easy modification
LABELS: |
hacktoberfest
hacktoberfest-accepted
hacktoberfest2024
steps:
- name: Add Hacktoberfest labels to issues
if: github.event_name == 'issues'
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.LABELS }}
continue-on-error: true # Avoid failures due to non-critical errors
id: add_labels_issues
- name: Add Hacktoberfest labels to pull requests
if: github.event_name == 'pull_request'
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.LABELS }}
continue-on-error: true # Avoid failures due to non-critical errors
id: add_labels_pr
# Validate if labels already exist to avoid duplicates
- name: Avoid duplicate labels on issues
if: github.event_name == 'issues' && steps.add_labels_issues.outcome == 'success'
run: |
echo "Checking if labels already exist on issue #${{ github.event.issue.number }}..."
existing_labels=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \
| jq -r '.[].name')
for label in ${{ env.LABELS }}; do
if [[ "$existing_labels" == *"$label"* ]]; then
echo "Label '$label' already exists, skipping."
else
echo "Adding label '$label'."
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \
-d "{\"labels\":[\"$label\"]}"
fi
done
- name: Avoid duplicate labels on pull requests
if: github.event_name == 'pull_request' && steps.add_labels_pr.outcome == 'success'
run: |
echo "Checking if labels already exist on pull request #${{ github.event.pull_request.number }}..."
existing_labels=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
| jq -r '.[].name')
for label in ${{ env.LABELS }}; do
if [[ "$existing_labels" == *"$label"* ]]; then
echo "Label '$label' already exists, skipping."
else
echo "Adding label '$label'."
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
-d "{\"labels\":[\"$label\"]}"
fi
done