hive-forge: add diff, notifications, notif-read, subscription verbs (closes #214)

This commit is contained in:
damocles 2026-05-21 23:35:41 +02:00
parent 8d3be74fd2
commit c8b544d340
3 changed files with 82 additions and 4 deletions

View file

@ -247,10 +247,82 @@ pkgs.writeShellApplication {
| jq -r '.browser_download_url'
}
cmd_diff() {
# diff <pr> [repo]
# Print the unified diff for a PR.
if [ $# -lt 1 ]; then echo "usage: hive-forge diff <pr> [repo]" >&2; exit 1; fi
local _n="$1" _repo="''${2:-$HIVE_FORGE_REPO}"
${pkgs.curl}/bin/curl -sf \
-H "Authorization: token $_token" \
-H "Accept: text/plain" \
"$FORGE_API/repos/$_repo/pulls/$_n.diff"
}
cmd_notifications() {
# notifications [--unread] [--limit N]
# List notifications. Without --unread, returns all (read + unread).
local _unread="" _limit="50"
while [ $# -gt 0 ]; do
case "$1" in
--unread) _unread="true"; shift ;;
--limit) _limit="$2"; shift 2 ;;
*) break ;;
esac
done
local _url="$FORGE_API/notifications?limit=$_limit"
if [ -z "$_unread" ]; then _url="''${_url}&all=true"; fi
forge_get "$_url" \
| jq '[.[] | {id,unread,reason,updated_at,
subject:{title:.subject.title,type:.subject.type,state:.subject.state},
repo:.repository.full_name}]'
}
cmd_notif_read() {
# notif-read <id>
# Mark a notification thread as read.
if [ $# -lt 1 ]; then echo "usage: hive-forge notif-read <id>" >&2; exit 1; fi
${pkgs.curl}/bin/curl -sf -X PATCH \
-H "Authorization: token $_token" \
-H "Accept: application/json" \
"$FORGE_API/notifications/threads/$1" > /dev/null
echo "ok"
}
cmd_subscription() {
# subscription [--watch|--ignore|--unwatch] [repo]
# Get or set the current user's watch subscription for a repo.
# No flag: print current subscription status as JSON.
# --watch: subscribe; --ignore: ignore; --unwatch: unsubscribe.
local _action="" _repo="$HIVE_FORGE_REPO"
while [ $# -gt 0 ]; do
case "$1" in
--watch) _action="watch"; shift ;;
--ignore) _action="ignore"; shift ;;
--unwatch) _action="unwatch"; shift ;;
*) _repo="$1"; shift ;;
esac
done
if [ -z "$_action" ]; then
forge_get "$FORGE_API/repos/$_repo/subscription" \
| jq '{subscribed,ignored}'
elif [ "$_action" = "unwatch" ]; then
forge_delete "$FORGE_API/repos/$_repo/subscription" > /dev/null
echo "unsubscribed"
else
local _subscribed="true" _ignored="false"
if [ "$_action" = "ignore" ]; then _subscribed="false"; _ignored="true"; fi
forge_post "$FORGE_API/repos/$_repo/subscription" \
"{\"subscribed\":$_subscribed,\"ignored\":$_ignored}" \
| jq '{subscribed,ignored}'
fi
}
VERB="''${1:-}"
if [ -z "$VERB" ]; then
echo "usage: hive-forge <verb> [args...]" >&2
echo "verbs: view, issue, pr, comment, assign, close, labels, pr-reviews, branches, tree-sha, attach-issue, attach-comment" >&2
echo "verbs: view, issue, pr, comment, assign, close, labels, pr-reviews," >&2
echo " branches, tree-sha, diff, notifications, notif-read, subscription," >&2
echo " attach-issue, attach-comment" >&2
exit 1
fi
shift
@ -266,11 +338,17 @@ pkgs.writeShellApplication {
pr-reviews) cmd_pr_reviews "$@" ;;
branches) cmd_branches "$@" ;;
tree-sha) cmd_tree_sha "$@" ;;
diff) cmd_diff "$@" ;;
notifications) cmd_notifications "$@" ;;
notif-read) cmd_notif_read "$@" ;;
subscription) cmd_subscription "$@" ;;
attach-issue) cmd_attach_issue "$@" ;;
attach-comment) cmd_attach_comment "$@" ;;
*)
echo "hive-forge: unknown verb '$VERB'" >&2
echo "verbs: view, issue, pr, comment, assign, close, labels, pr-reviews, branches, tree-sha, attach-issue, attach-comment" >&2
echo "verbs: view, issue, pr, comment, assign, close, labels, pr-reviews," >&2
echo " branches, tree-sha, diff, notifications, notif-read, subscription," >&2
echo " attach-issue, attach-comment" >&2
exit 1
;;
esac