hive-forge: fix comment --body flag swallowing, add comment-edit verb

This commit is contained in:
damocles 2026-05-22 21:31:41 +02:00 committed by Mara
parent 3f08051bda
commit 20d2b48fe5

View file

@ -130,24 +130,56 @@ pkgs.writeShellApplication {
} }
cmd_comment() { cmd_comment() {
# comment <number> [body | -f <file> | - for stdin] # comment <number> [--body <text> | -f <file> | -]
# Post a comment on an issue or PR. # Post a comment on an issue or PR.
if [ $# -lt 1 ]; then echo "usage: hive-forge comment <number> [body | -f <file> | -]" >&2; exit 1; fi # Accepts --body <text> (consistent with issue-create/pr-create),
# -f <file>, - (stdin), or a bare positional body string.
if [ $# -lt 1 ]; then echo "usage: hive-forge comment <number> [--body <text> | -f <file> | -]" >&2; exit 1; fi
local _n="$1"; shift local _n="$1"; shift
local _body local _body _repo="$HIVE_FORGE_REPO"
if [ $# -eq 0 ] || [ "''${1:-}" = "-" ]; then if [ $# -eq 0 ] || [ "''${1:-}" = "-" ]; then
_body=$(cat) _body=$(cat)
elif [ "''${1:-}" = "--body" ]; then
_body="$2"
elif [ "''${1:-}" = "-f" ]; then elif [ "''${1:-}" = "-f" ]; then
_body=$(cat "$2") _body=$(cat "$2")
elif [[ "''${1:-}" == --* ]]; then
echo "hive-forge comment: unknown flag '$1' (did you mean --body?)" >&2; exit 1
else else
_body="$*" _body="$*"
fi fi
local _payload local _payload
_payload=$(jq -n --arg body "$_body" '{body:$body}') _payload=$(jq -n --arg body "$_body" '{body:$body}')
forge_post "$FORGE_API/repos/$HIVE_FORGE_REPO/issues/$_n/comments" "$_payload" \ forge_post "$FORGE_API/repos/$_repo/issues/$_n/comments" "$_payload" \
| jq '{id,url:.html_url}' | jq '{id,url:.html_url}'
} }
cmd_comment_edit() {
# comment-edit <id> [--body <text> | -f <file> | -] [repo]
# Edit an existing comment by its id.
if [ $# -lt 1 ]; then echo "usage: hive-forge comment-edit <id> [--body <text> | -f <file> | -] [repo]" >&2; exit 1; fi
local _id="$1"; shift
local _body _repo="$HIVE_FORGE_REPO"
if [ $# -eq 0 ] || [ "''${1:-}" = "-" ]; then
_body=$(cat)
elif [ "''${1:-}" = "--body" ]; then
_body="$2"; shift 2 || true
if [ $# -gt 0 ]; then _repo="$1"; fi
elif [ "''${1:-}" = "-f" ]; then
_body=$(cat "$2"); shift 2 || true
if [ $# -gt 0 ]; then _repo="$1"; fi
elif [[ "''${1:-}" == --* ]]; then
echo "hive-forge comment-edit: unknown flag '$1'" >&2; exit 1
else
_body="$1"; shift
if [ $# -gt 0 ]; then _repo="$1"; fi
fi
local _payload
_payload=$(jq -n --arg body "$_body" '{body:$body}')
forge_patch "$FORGE_API/repos/$_repo/issues/comments/$_id" "$_payload" \
| jq '{id,user:.user.login,url:.html_url}'
}
cmd_assign() { cmd_assign() {
# assign <number> <user> [--remove] # assign <number> <user> [--remove]
# Assign or unassign a user on an issue or PR. # Assign or unassign a user on an issue or PR.
@ -448,8 +480,8 @@ pkgs.writeShellApplication {
if [ -z "$VERB" ]; then if [ -z "$VERB" ]; then
echo "usage: hive-forge <verb> [args...]" >&2 echo "usage: hive-forge <verb> [args...]" >&2
echo "verbs: view, issue, issue-create, issue-edit, pr, pr-create, comment, comment-show," >&2 echo "verbs: view, issue, issue-create, issue-edit, pr, pr-create, comment, comment-show," >&2
echo " assign, close, labels, milestone, pr-reviews, branches, tree-sha, diff," >&2 echo " comment-edit, assign, close, labels, milestone, pr-reviews, branches, tree-sha," >&2
echo " subscription, attach-issue, attach-comment" >&2 echo " diff, subscription, attach-issue, attach-comment" >&2
exit 1 exit 1
fi fi
shift shift
@ -463,6 +495,7 @@ pkgs.writeShellApplication {
pr-create) cmd_pr_create "$@" ;; pr-create) cmd_pr_create "$@" ;;
comment) cmd_comment "$@" ;; comment) cmd_comment "$@" ;;
comment-show) cmd_comment_show "$@" ;; comment-show) cmd_comment_show "$@" ;;
comment-edit) cmd_comment_edit "$@" ;;
assign) cmd_assign "$@" ;; assign) cmd_assign "$@" ;;
close) cmd_close "$@" ;; close) cmd_close "$@" ;;
labels) cmd_labels "$@" ;; labels) cmd_labels "$@" ;;
@ -477,8 +510,8 @@ pkgs.writeShellApplication {
*) *)
echo "hive-forge: unknown verb '$VERB'" >&2 echo "hive-forge: unknown verb '$VERB'" >&2
echo "verbs: view, issue, issue-create, issue-edit, pr, pr-create, comment, comment-show," >&2 echo "verbs: view, issue, issue-create, issue-edit, pr, pr-create, comment, comment-show," >&2
echo " assign, close, labels, milestone, pr-reviews, branches, tree-sha, diff," >&2 echo " comment-edit, assign, close, labels, milestone, pr-reviews, branches, tree-sha," >&2
echo " subscription, attach-issue, attach-comment" >&2 echo " diff, subscription, attach-issue, attach-comment" >&2
exit 1 exit 1
;; ;;
esac esac