-
Notifications
You must be signed in to change notification settings - Fork 1
87 lines (75 loc) · 2.36 KB
/
labeler.yaml
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
81
82
83
84
85
86
87
name: PR Labeler
on:
pull_request:
types: [opened, synchronize]
branches:
- main
jobs:
labeler:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch all branches
run: git fetch --all
- name: Extract commit messages
run: |
COMMITS=$(git log --format=%B origin/main..HEAD)
echo "$COMMITS"
echo "$COMMITS" > commits.txt
- name: Debug - Print commits
run: cat commits.txt
- name: Set labels based on commit messages
id: set-labels
run: |
labels=()
while IFS= read -r commit; do
echo "Processing commit: $commit"
if [[ $commit =~ ^feat ]]; then
labels+=("feature")
elif [[ $commit =~ ^fix ]]; then
labels+=("bugfix")
elif [[ $commit =~ ^docs ]]; then
labels+=("documentation")
elif [[ $commit =~ ^style ]]; then
labels+=("style")
elif [[ $commit =~ ^refactor ]]; then
labels+=("refactor")
elif [[ $commit =~ ^test ]]; then
labels+=("test")
elif [[ $commit =~ ^ci ]]; then
labels+=("ci")
elif [[ $commit =~ ^chore ]]; then
labels+=("chore")
fi
done < commits.txt
# Remove duplicate labels and join them as a newline-separated string
unique_labels=$(printf "%s\n" "${labels[@]}" | sort -u)
# Debug output for unique labels
echo "Unique labels:"
echo "$unique_labels"
# Set the output as a newline-separated string
echo "labels<<EOF" >> $GITHUB_OUTPUT
echo "$unique_labels" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Add labels to PR
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
labels: ${{ steps.set-labels.outputs.labels }}
- name: Assign PR creator
uses: actions/github-script@v6
with:
script: |
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
assignees: [context.actor]
})