Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: script to add label to PR based on edited package #26

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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