diff --git a/nix/packages/hive-forge-tools.nix b/nix/packages/hive-forge-tools.nix index 58eb22a..39f05aa 100644 --- a/nix/packages/hive-forge-tools.nix +++ b/nix/packages/hive-forge-tools.nix @@ -130,24 +130,56 @@ pkgs.writeShellApplication { } cmd_comment() { - # comment [body | -f | - for stdin] + # comment [--body | -f | -] # Post a comment on an issue or PR. - if [ $# -lt 1 ]; then echo "usage: hive-forge comment [body | -f | -]" >&2; exit 1; fi + # Accepts --body (consistent with issue-create/pr-create), + # -f , - (stdin), or a bare positional body string. + if [ $# -lt 1 ]; then echo "usage: hive-forge comment [--body | -f | -]" >&2; exit 1; fi local _n="$1"; shift - local _body + local _body _repo="$HIVE_FORGE_REPO" if [ $# -eq 0 ] || [ "''${1:-}" = "-" ]; then _body=$(cat) + elif [ "''${1:-}" = "--body" ]; then + _body="$2" elif [ "''${1:-}" = "-f" ]; then _body=$(cat "$2") + elif [[ "''${1:-}" == --* ]]; then + echo "hive-forge comment: unknown flag '$1' (did you mean --body?)" >&2; exit 1 else _body="$*" fi local _payload _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}' } + cmd_comment_edit() { + # comment-edit [--body | -f | -] [repo] + # Edit an existing comment by its id. + if [ $# -lt 1 ]; then echo "usage: hive-forge comment-edit [--body | -f | -] [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() { # assign [--remove] # Assign or unassign a user on an issue or PR. @@ -448,8 +480,8 @@ pkgs.writeShellApplication { if [ -z "$VERB" ]; then echo "usage: hive-forge [args...]" >&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 " subscription, attach-issue, attach-comment" >&2 + echo " comment-edit, assign, close, labels, milestone, pr-reviews, branches, tree-sha," >&2 + echo " diff, subscription, attach-issue, attach-comment" >&2 exit 1 fi shift @@ -463,6 +495,7 @@ pkgs.writeShellApplication { pr-create) cmd_pr_create "$@" ;; comment) cmd_comment "$@" ;; comment-show) cmd_comment_show "$@" ;; + comment-edit) cmd_comment_edit "$@" ;; assign) cmd_assign "$@" ;; close) cmd_close "$@" ;; labels) cmd_labels "$@" ;; @@ -477,8 +510,8 @@ pkgs.writeShellApplication { *) echo "hive-forge: unknown verb '$VERB'" >&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 " subscription, attach-issue, attach-comment" >&2 + echo " comment-edit, assign, close, labels, milestone, pr-reviews, branches, tree-sha," >&2 + echo " diff, subscription, attach-issue, attach-comment" >&2 exit 1 ;; esac