From ae7b6fdbcdb56185e90641e503bc27cf4743110c Mon Sep 17 00:00:00 2001 From: syntactically <168595099+syntactically@users.noreply.github.com> Date: Thu, 30 Jan 2025 22:39:57 +0000 Subject: [PATCH] Update label checker for new lifecycle labels Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com> --- .github/workflows/IssueLabelChecker.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/IssueLabelChecker.yml b/.github/workflows/IssueLabelChecker.yml index 266483508..2ba380c36 100644 --- a/.github/workflows/IssueLabelChecker.yml +++ b/.github/workflows/IssueLabelChecker.yml @@ -14,9 +14,22 @@ jobs: - uses: actions/checkout@v4 - name: Check and Add label run: | - LABELS=$(gh issue view ${{ github.event.issue.number }} --json labels -q '.labels[].name') - if [[ $LABELS != *"needs review"* ]]; then - gh issue edit ${{ github.event.issue.number }} --add-label "needs review" + # The cryptic head -c -1 is because otherwise gh always terminates output with a newline + readarray -d $'\0' lifecycles < <(gh issue view ${{ github.event.issue.number }} --json labels -q '[.labels[] | .name | select(startswith("lifecycle/"))] | join("\u0000")' | head -c -1) + if [[ ${#lifecycles[@]} -ne 1 ]]; then + if [[ ${#lifecycles[@]} -ge 1 ]]; then + echo 'Too many lifecycle labels; replacing all with `lifecycle/needs review`' + fi + commands=() + for label in "${lifecycles[@]}"; do + if [[ "$label" != "lifecycle/needs review" ]]; then + echo "Removing label ${label}" + commands+=("--remove-label" "${label}") + fi + done + echo 'Adding `lifecycle/needs review`' + commands+=("--add-label" "lifecycle/needs review") + gh issue edit ${{ github.event.issue.number }} "${commands[@]}" fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file