| 1 | #!/usr/bin/env bash |
| 2 | # Resolve a review thread on a PR (marks the conversation as done in the UI). |
| 3 | # |
| 4 | # Usage: |
| 5 | # resolve-thread.sh <thread-node-id> |
| 6 | # |
| 7 | # <thread-node-id> is the GraphQL id from review-threads.json -> .[].id. |
| 8 | # It looks like "PRRT_kwDO..." -- not the numeric REST id. |
| 9 | # |
| 10 | # Resolving a thread does NOT require a reply, but the convention is to reply |
| 11 | # first then resolve. See SKILL.md. |
| 12 | |
| 13 | set -euo pipefail |
| 14 | |
| 15 | # shellcheck source=./_lib.sh |
| 16 | # shellcheck disable=SC1091 |
| 17 | source "$(dirname "$0")/_lib.sh" |
| 18 | pr_require_gh |
| 19 | |
| 20 | THREAD_ID="${1:?usage: $0 <thread-node-id>}" |
| 21 | |
| 22 | # Review-thread node IDs follow the pattern `PRRT_<base64ish>`. Validate |
| 23 | # the prefix + the body charset so a malformed value can't reach the API. |
| 24 | if [[ ! "${THREAD_ID}" =~ ^PRRT_[A-Za-z0-9_-]+$ ]]; then |
| 25 | echo -e "${PR_RED}[ERROR]${PR_NC} thread-node-id must look like 'PRRT_...' (got: '${THREAD_ID}')" >&2 |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | # Fail fast on non-GitHub remotes. The mutation operates by node ID and |
| 30 | # does not need the slug, but this script is GitHub-only -- making that |
| 31 | # explicit at entry catches misconfiguration earlier than letting the |
| 32 | # mutation hit a non-github API. |
| 33 | pr_require_slug >/dev/null |
| 34 | |
| 35 | # The single-quoted GraphQL string has $threadId as a placeholder. |
| 36 | # shellcheck disable=SC2016 |
| 37 | gh api graphql -F threadId="${THREAD_ID}" -f query=' |
| 38 | mutation($threadId:ID!) { |
| 39 | resolveReviewThread(input: {threadId: $threadId}) { |
| 40 | thread { id isResolved } |
| 41 | } |
| 42 | } |
| 43 | ' --jq '.data.resolveReviewThread.thread | "resolved=\(.isResolved) id=\(.id)"' |