-
-
Notifications
You must be signed in to change notification settings - Fork 251
64 lines (53 loc) · 1.87 KB
/
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
name: Label Pull Requests
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
label-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get changed files
id: changed-files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
git diff --name-only origin/${{ github.base_ref }} > changed-files.txt
echo "##[group]Changed files"
cat changed-files.txt
echo "##[endgroup]"
echo "::set-output name=files::$(cat changed-files.txt)"
- name: Add labels to PR
env:
GH_TOKEN: "${{ github.token }}"
FILES: ${{ steps.changed-files.outputs.files }}
run: |
# Labels
LABEL_NEW="pr: new extension"
LABEL_CHANGE="pr: change existing extension"
LABEL_OTHER="pr: other"
# Folder to monitor
TARGET_FOLDER="extensions/"
# Initialize flags
ADD_NEW="false"
MODIFY_EXISTING="false"
# Process each file
while IFS= read -r FILE; do
if [[ "$FILE" == $TARGET_FOLDER* ]]; then
if ! git ls-tree -r origin/${{ github.base_ref }} --name-only | grep -q "^$FILE$"; then
ADD_NEW="true"
else
MODIFY_EXISTING="true"
fi
fi
done < changed-files.txt
# Add labels
if [[ "$ADD_NEW" == "true" ]]; then
gh pr edit ${{ github.event.number }} --add-label "$LABEL_NEW"
fi
if [[ "$MODIFY_EXISTING" == "true" ]]; then
gh pr edit ${{ github.event.number }} --add-label "$LABEL_CHANGE"
fi
if [[ "$ADD_NEW" == "false" && "$MODIFY_EXISTING" == "false" ]]; then
gh pr edit ${{ github.event.number }} --add-label "$LABEL_OTHER"
fi