master
sh 41 lines 1.36 KB
Raw
1 #!/usr/bin/env bash
2 # List open (unresolved) review threads on a PR with the comments inside each.
3 # Usage:
4 # list-open-threads.sh <pr-number> # full bodies
5 # list-open-threads.sh <pr-number> --short # one-line per thread
6 #
7 # Reads from the cached fetch-all.sh dump. Run fetch-all.sh first.
8
9 set -euo pipefail
10
11 # shellcheck source=./_lib.sh
12 # shellcheck disable=SC1091
13 source "$(dirname "$0")/_lib.sh"
14
15 PR="${1:?usage: $0 <pr-number> [--short]}"
16 pr_require_numeric "${PR}"
17 SHORT=0
18 [[ "${2:-}" == "--short" ]] && SHORT=1
19
20 DIR="$(pr_state_dir "${PR}")"
21 FILE="${DIR}/review-threads.json"
22 if [[ ! -f "${FILE}" || ! -r "${FILE}" || ! -s "${FILE}" ]]; then
23 echo -e "${PR_RED}Missing ${FILE}. Run fetch-all.sh ${PR} first.${PR_NC}" >&2
24 exit 1
25 fi
26
27 if (( SHORT )); then
28 jq -r '
29 .[]
30 | select(.isResolved | not)
31 | "\(.id) | \(.path):\(.line // "?") | \(.comments.nodes[0].author.login)"
32 ' "${FILE}" | column -t -s '|'
33 else
34 jq -r '
35 .[]
36 | select(.isResolved | not)
37 | "================================================================\nTHREAD: \(.id)\nFile: \(.path):\(.line // "?")\nOutdated: \(.isOutdated)\n----------------------------------------------------------------\n" + (
38 [.comments.nodes[] | "[\(.author.login) at \(.createdAt)]\n\(.body)\n -> \(.url)\n"] | join("\n")
39 )
40 ' "${FILE}"
41 fi