Skip to content

Commit dad29d8

Browse files
committed
ci: script to add label to PR based on edited package
Signed-off-by: Michael Molisani <[email protected]>
1 parent 2bb4b8d commit dad29d8

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

.github/workflows/pr_labels.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Add package labels to PR
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
10+
permissions:
11+
actions: read
12+
contents: read
13+
pull-requests: write
14+
15+
jobs:
16+
main:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
cache: "npm"
27+
28+
- run: npm ci --legacy-peer-deps
29+
- uses: nrwl/nx-set-shas@v4
30+
31+
- run: ./scripts/add_labels_to_pr.sh
32+
env:
33+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
GH_REPO: ${{ github.repository }}
35+
PR_NUMBER: ${{ github.event.pull_request.number }}

scripts/add_labels_to_pr.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
for $path in $(git diff main...HEAD --name-only); do
4+
if [[ $path == packages/core/* ]] && [[ -z "$ADDED_CORE_LABEL" ]]; then
5+
echo "Change found in packages/core, adding label for core"
6+
gh pr edit $PR_NUMBER --add-label "core ⚙"
7+
ADDED_CORE_LABEL = 1
8+
fi
9+
10+
if [[ $path == packages/auto-complete/* ]] && [[ -z "$ADDED_AUTO_COMPLETE_LABEL" ]]; then
11+
echo "Change found in packages/auto-complete, adding label for auto-complete"
12+
gh pr edit $PR_NUMBER --add-label "auto-complete 🔮"
13+
ADDED_AUTO_COMPLETE_LABEL = 1
14+
fi
15+
16+
if [[ $path == packages/create-app/* ]] && [[ -z "$ADDED_CREATE_APP_LABEL" ]]; then
17+
echo "Change found in packages/create-app, adding label for create-app"
18+
gh pr edit $PR_NUMBER --add-label "create-app 📂"
19+
ADDED_CREATE_APP_LABEL = 1
20+
fi
21+
done

0 commit comments

Comments
 (0)