Skip to content

Instantly share code, notes, and snippets.

@FATESAIKOU
Created March 22, 2026 14:35
Show Gist options
  • Select an option

  • Save FATESAIKOU/393f334fd07d848d7c8de935284625e7 to your computer and use it in GitHub Desktop.

Select an option

Save FATESAIKOU/393f334fd07d848d7c8de935284625e7 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 檢查是否有輸入參數
if [ -z "$1" ]; then
echo "使用方式: $0 <issue_url>"
exit 1
fi
ISSUE_URL=$1
# 從 URL 中解析 Owner, Repo 和 Issue Number
# 支援格式: https://github.com/owner/repo/issues/123
OWNER_REPO=$(echo $ISSUE_URL | sed -E 's|https://github.com/([^/]+/[^/]+)/issues/[0-9]+|\1|')
ISSUE_NUM=$(echo $ISSUE_URL | sed -E 's|.*/issues/([0-9]+)|\1|')
echo "正在處理: $OWNER_REPO 的第 #$ISSUE_NUM 號 Issue..."
# 1. 抓取所有留言的 ID
COMMENT_IDS=$(gh api "repos/$OWNER_REPO/issues/$ISSUE_NUM/comments" --jq '.[].id')
if [ -z "$COMMENT_IDS" ]; then
echo "此 Issue 沒有任何留言或找不到該 Issue。"
exit 0
fi
# 2. 逐一刪除
echo "開始刪除留言..."
for ID in $COMMENT_IDS; do
echo "正在刪除留言 ID: $ID"
gh api -X DELETE "repos/$OWNER_REPO/issues/comments/$ID" --silent
done
echo "完成!所有留言已清空。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment