1 #!/usr/bin/env bash
2 #
3 # Fetches the current labels on a GitHub issue.
4 # Usage: ./scripts/get_labels.sh [issue_number]
5 #
6 # If issue_number is not provided, reads from the workflow event payload.
7 #
8
9 set -euo pipefail
10
11 if [[ -n "${1:-}" ]]; then
12 ISSUE="$1"
13 else
14 ISSUE=$(jq -r '.issue.number // empty' "${GITHUB_EVENT_PATH:?GITHUB_EVENT_PATH not set}")
15 fi
16
17 if ! [[ "$ISSUE" =~ ^[0-9]+$ ]]; then
18 echo "Error: no valid issue number provided or found in event payload" >&2
19 exit 1
20 fi
21
22 gh issue view "$ISSUE" --json labels --jq '[.labels[].name]'