-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathpr-resolve
More file actions
executable file
·74 lines (66 loc) · 2.2 KB
/
Copy pathpr-resolve
File metadata and controls
executable file
·74 lines (66 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# pr-resolve — list and resolve PR review threads in batch.
#
# Usage:
# scripts/pr-resolve list <PR>
# List unresolved review threads, one per line, TAB-separated:
# <thread_id>\t<comment_id>\t<author>\t<path>\t<body_first_120_chars>
#
# scripts/pr-resolve reply <PR> <CID> <TID> <BODY>
# Reply to the thread starter, resolve the thread, and add a +1
# reaction in one call. Use this for both "fixed" replies and
# pushback replies — the reply body conveys whether you agreed
# or not.
#
# Owner/repo are derived from `gh repo view` in the current repo.
#
# Requires: gh (authenticated) and jq.
set -euo pipefail
usage() {
sed -n '2,16p' "$0" | sed 's|^# \{0,1\}||'
exit "${1:-1}"
}
[ $# -ge 1 ] || usage
cmd=$1; shift
read -r OWNER REPO < <(gh repo view --json owner,name --jq '"\(.owner.login) \(.name)"')
case "$cmd" in
list)
[ $# -eq 1 ] || usage
PR=$1
gh api graphql -f query='
query($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
reviewThreads(first: 100) {
nodes {
id
isResolved
path
comments(first: 1) {
nodes { databaseId author { login } body }
}
}
}
}
}
}' -f owner="$OWNER" -f repo="$REPO" -F pr="$PR" \
| jq -r '.data.repository.pullRequest.reviewThreads.nodes
| map(select(.isResolved == false))
| .[]
| "\(.id)\t\(.comments.nodes[0].databaseId)\t\(.comments.nodes[0].author.login)\t\(.path)\t\(.comments.nodes[0].body | gsub("\n"; " ") | .[0:120])"'
;;
reply)
[ $# -eq 4 ] || usage
PR=$1; CID=$2; TID=$3; BODY=$4
gh api -X POST "repos/$OWNER/$REPO/pulls/$PR/comments/$CID/replies" \
-f body="$BODY" --silent
gh api graphql -f query='mutation($t: ID!) { resolveReviewThread(input: {threadId: $t}) { thread { isResolved } } }' \
-f t="$TID" --silent
gh api -X POST "repos/$OWNER/$REPO/pulls/comments/$CID/reactions" \
-f content="+1" --silent
echo "ok $TID"
;;
*)
usage
;;
esac