reply-github-pr (727B)
1 #!/usr/bin/env bash 2 3 set -eou pipefail 4 5 tmp=$(mktemp) 6 reply="$(mktemp).eml" 7 8 function cleanup() { 9 rm -f "$tmp" 10 } 11 12 trap cleanup EXIT 13 14 cat > "$tmp" 15 16 replyto=$(grep -i ^reply-to "$tmp" | head -n1 | sed -E -n 's,^reply-to: (.*)$,\1,pI') 17 printf "reply-to %s\n" "$replyto" >&2 18 link=$(<"$tmp" sed -E -n 's,.*(https://github.com/[^/]+/[^/]+/pull/[0-9]+).*,\1.patch,p' | head -n1 | grep .) 19 20 printf "fetching patch %s\n" "$link" >&2 21 curl -sL "$link" | notmuch insert +insertedreply 22 23 id=$(notmuch search --output=messages tag:insertedreply | head -n1 | grep .) 24 25 notmuch reply "$id" | sed "/^To:/a Cc: $replyto" > "$reply" 26 notmuch search --output=files "$id" | xargs rm -f 27 notmuch new &>/dev/null 28 29 $EDITOR "$reply" 30 printf "%s\n" "$reply"