ci/woodpecker/pr/ci Pipeline is pending
- Option-like value = any token starting with '-' followed by an alphanumeric (-h, -ab, --help); multi-character short clusters were still accepted (codex blocker). Bare '-' is reserved (future stdin). - usage_error now prints the usage text to stderr as well (codex should-fix): usage output belonged to stdout only on the help path. - 16/16 usage-contract suites green.
60 lines
2.0 KiB
Bash
Executable File
60 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# milestone-list.sh - List milestones on GitHub or Gitea
|
|
# Usage: milestone-list.sh [-s <state>]
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/detect-platform.sh"
|
|
|
|
# Parse arguments
|
|
# Usage-error contract (R4, 2026-08-28): usage errors print to STDERR and exit 2,
|
|
# distinct from provider, credential, and verification failures (exit 1).
|
|
usage_error() {
|
|
echo "Error: $*" >&2
|
|
echo "Usage: milestone-list.sh [-s <state>] (see --help)" >&2
|
|
exit 2
|
|
}
|
|
|
|
STATE="open"
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-s|--state)
|
|
[[ $# -ge 2 && "$2" != - && "$2" != --* && ! "$2" =~ ^-[[:alnum:]] ]] || usage_error "option $1 requires a value (option-like values are rejected; bare - is reserved)"
|
|
STATE="$2"
|
|
shift 2
|
|
;;
|
|
-h|--help)
|
|
echo "Usage: milestone-list.sh [-s <state>]"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -s, --state Filter by state: open, closed, all (default: open)"
|
|
echo " -h, --help Show this help"
|
|
exit 0
|
|
;;
|
|
*)
|
|
usage_error "unknown option: $1"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
detect_platform >/dev/null
|
|
|
|
if [[ "$PLATFORM" == "github" ]]; then
|
|
prov_rc=0
|
|
gh api "/repos/{owner}/{repo}/milestones?state=$STATE" --jq '.[] | "\(.title) (\(.state)) - \(.open_issues) open, \(.closed_issues) closed"' || prov_rc=$?
|
|
[[ "$prov_rc" -eq 0 ]] || { echo "Error: provider command failed (exit ${prov_rc}; provider failure, not a usage error)" >&2; exit 1; }
|
|
elif [[ "$PLATFORM" == "gitea" ]]; then
|
|
REPO_ARGS=$(get_gitea_repo_args) || {
|
|
echo "Error: Could not resolve Gitea repo/login for remote host" >&2
|
|
exit 1
|
|
}
|
|
prov_rc=0
|
|
tea milestone list $REPO_ARGS || prov_rc=$?
|
|
[[ "$prov_rc" -eq 0 ]] || { echo "Error: provider command failed (exit ${prov_rc}; provider failure, not a usage error)" >&2; exit 1; }
|
|
else
|
|
echo "Error: Unknown platform"
|
|
exit 1
|
|
fi
|