From 52be94848c58d9864e44d21986bb121c20e98c84 Mon Sep 17 00:00:00 2001 From: Michael Molisani Date: Mon, 21 Oct 2024 10:17:36 -0400 Subject: [PATCH] ci: script to add label to PR based on diff Signed-off-by: Michael Molisani --- .github/workflows/pr_labels.yml | 27 +++++++++++++++++++++ scripts/add_labels_to_pr.sh | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/pr_labels.yml create mode 100755 scripts/add_labels_to_pr.sh diff --git a/.github/workflows/pr_labels.yml b/.github/workflows/pr_labels.yml new file mode 100644 index 0000000..e97e8ab --- /dev/null +++ b/.github/workflows/pr_labels.yml @@ -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 }} diff --git a/scripts/add_labels_to_pr.sh b/scripts/add_labels_to_pr.sh new file mode 100755 index 0000000..9129f30 --- /dev/null +++ b/scripts/add_labels_to_pr.sh @@ -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