Skip to content

Commit

Permalink
ci: script to add label to PR based on diff
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Molisani <[email protected]>
  • Loading branch information
molisani authored and mkubilayk committed Oct 22, 2024
1 parent 2bb4b8d commit 52be948
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/pr_labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Add labels to PR

on:
pull_request:
types:
- opened
- reopened
- synchronize

permissions:
actions: read
contents: read
pull-requests: write

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- run: ./scripts/add_labels_to_pr.sh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
43 changes: 43 additions & 0 deletions scripts/add_labels_to_pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

diff_result=$(git diff --name-only origin/main..HEAD)

if [[ "${diff_result[*]}" =~ packages/core/* ]]; then
echo "Change found in packages/core, adding label for core"
gh pr edit $PR_NUMBER --add-label "core ⚙"
else
echo "No changes found in packages/core, removing label for core"
gh pr edit $PR_NUMBER --remove-label "core ⚙"
fi

if [[ "${diff_result[*]}" =~ packages/auto-complete/* ]]; then
echo "Change found in packages/auto-complete, adding label for auto-complete"
gh pr edit $PR_NUMBER --add-label "auto-complete 🔮"
else
echo "No changes found in packages/auto-complete, removing label for auto-complete"
gh pr edit $PR_NUMBER --remove-label "auto-complete 🔮"
fi

if [[ "${diff_result[*]}" =~ packages/create-app/* ]]; then
echo "Change found in packages/create-app, adding label for create-app"
gh pr edit $PR_NUMBER --add-label "create-app 📂"
else
echo "No changes found in packages/create-app, removing label for create-app"
gh pr edit $PR_NUMBER --remove-label "create-app 📂"
fi

if [[ "${diff_result[*]}" =~ docs/* ]]; then
echo "Change found in docs, adding label for documentation"
gh pr edit $PR_NUMBER --add-label "documentation 📝"
else
echo "No changes found in docs, removing label for documentation"
gh pr edit $PR_NUMBER --remove-label "documentation 📝"
fi

if [[ "${diff_result[*]}" =~ .github/workflows/* ]]; then
echo "Change found in .github/workflows, adding label for ci"
gh pr edit $PR_NUMBER --add-label "ci 🤖"
else
echo "No changes found in .github/workflows, removing label for ci"
gh pr edit $PR_NUMBER --remove-label "ci 🤖"
fi

0 comments on commit 52be948

Please sign in to comment.