Skip to content

Commit

Permalink
ci: refactor add_labels_to_pr to use associative array
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Molisani <[email protected]>
  • Loading branch information
molisani committed Oct 22, 2024
1 parent ecc9099 commit bc34f48
Showing 1 changed file with 17 additions and 38 deletions.
55 changes: 17 additions & 38 deletions scripts/add_labels_to_pr.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
#!/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
declare -A path_label_mapping

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
path="packages/core"; path_label_mapping[$path]="core ⚙"
path="packages/auto-complete"; path_label_mapping[$path]="auto-complete 🔮"
path="packages/create-app"; path_label_mapping[$path]="create-app 📂"
path="docs"; path_label_mapping[$path]="documentation 📝"
path=".github/workflows"; path_label_mapping[$path]="ci 🤖"

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
diff_result=$(git diff --name-only origin/main..HEAD)

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
for path in "${!path_label_mapping[@]}"
do
if [[ "${diff_result[*]}" =~ $path/* ]]; then
echo "Change found in $path, adding label ${path_label_mapping[$path]}"
gh pr edit $DRONE_PULL_REQUEST --add-label "${path_label_mapping[$path]}"
else
echo "No changes found in $path, removing label ${path_label_mapping[$path]}"
gh pr edit $DRONE_PULL_REQUEST --remove-label "${path_label_mapping[$path]}"
fi
done

0 comments on commit bc34f48

Please sign in to comment.