close-stale-issues.sh 1.0 KB

12345678910111213141516171819202122232425
  1. #!/usr/bin/env bash
  2. # 关闭过时的自动升级失败 Issue(升级成功后,旧版本的失败记录均已过时)
  3. #
  4. # Close stale auto-upgrade failure Issues (after a successful upgrade, older failure records are all stale)
  5. # Usage: close-stale-issues.sh
  6. #
  7. # 测试注入:设置 GH=/path/to/mock 可替换 gh 命令(用于单测)
  8. #
  9. # Test injection: set GH=/path/to/mock to substitute the gh command (used by unit tests)
  10. set -euo pipefail
  11. GH_BIN="${GH:-gh}"
  12. JSON="$("$GH_BIN" issue list --state open --search 'in:title "[自动升级]"' --json title,number --limit 50 2>/dev/null || true)"
  13. [ -n "$JSON" ] || { echo "无过时的失败 Issue"; exit 0; }
  14. # 本次升级已成功:所有自动升级失败 Issue 均视为过时,全部关闭
  15. #
  16. # This upgrade succeeded: every auto-upgrade failure Issue is now stale; close them all
  17. STALE="$(jq -r '.[] | .number' <<<"$JSON")"
  18. for n in $STALE; do
  19. echo "关闭过时 Issue #$n"
  20. "$GH_BIN" issue close "$n"
  21. done
  22. [ -n "$STALE" ] || echo "无过时的失败 Issue"