Skip to content

Commit ae7b6fd

Browse files
Update label checker for new lifecycle labels
Signed-off-by: Lucy Menon <[email protected]>
1 parent e6fe869 commit ae7b6fd

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

.github/workflows/IssueLabelChecker.yml

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- name: Check and Add label
1616
run: |
17-
LABELS=$(gh issue view ${{ github.event.issue.number }} --json labels -q '.labels[].name')
18-
if [[ $LABELS != *"needs review"* ]]; then
19-
gh issue edit ${{ github.event.issue.number }} --add-label "needs review"
17+
# The cryptic head -c -1 is because otherwise gh always terminates output with a newline
18+
readarray -d $'\0' lifecycles < <(gh issue view ${{ github.event.issue.number }} --json labels -q '[.labels[] | .name | select(startswith("lifecycle/"))] | join("\u0000")' | head -c -1)
19+
if [[ ${#lifecycles[@]} -ne 1 ]]; then
20+
if [[ ${#lifecycles[@]} -ge 1 ]]; then
21+
echo 'Too many lifecycle labels; replacing all with `lifecycle/needs review`'
22+
fi
23+
commands=()
24+
for label in "${lifecycles[@]}"; do
25+
if [[ "$label" != "lifecycle/needs review" ]]; then
26+
echo "Removing label ${label}"
27+
commands+=("--remove-label" "${label}")
28+
fi
29+
done
30+
echo 'Adding `lifecycle/needs review`'
31+
commands+=("--add-label" "lifecycle/needs review")
32+
gh issue edit ${{ github.event.issue.number }} "${commands[@]}"
2033
fi
2134
env:
2235
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)