hive-forge: add pr-create and issue-create verbs, closes #209

This commit is contained in:
damocles 2026-05-21 22:47:36 +02:00
parent 5de795c55f
commit 0615b0521f
3 changed files with 65 additions and 6 deletions

View file

@ -221,6 +221,63 @@ pkgs.writeShellApplication {
| jq -r '.tree.sha // .sha'
}
cmd_pr_create() {
# pr-create --title <title> --head <branch> [--base <base>] [--body <body>] [--draft] [repo]
# Create a pull request. Prints the PR URL on success.
local _title="" _head="" _base="main" _body="" _draft="false" _repo="$HIVE_FORGE_REPO"
while [ $# -gt 0 ]; do
case "$1" in
--title) _title="$2"; shift 2 ;;
--head) _head="$2"; shift 2 ;;
--base) _base="$2"; shift 2 ;;
--body) _body="$2"; shift 2 ;;
--draft) _draft="true"; shift ;;
*) _repo="$1"; shift ;;
esac
done
if [ -z "$_title" ] || [ -z "$_head" ]; then
echo "usage: hive-forge pr-create --title <title> --head <branch> [--base <base>] [--body <body>] [--draft] [repo]" >&2
exit 1
fi
local _payload
_payload=$(jq -n \
--arg title "$_title" \
--arg head "$_head" \
--arg base "$_base" \
--arg body "$_body" \
--argjson draft "$_draft" \
'{title:$title,head:$head,base:$base,body:$body,draft:$draft}')
forge_post "$FORGE_API/repos/$_repo/pulls" "$_payload" \
| jq -r '.html_url'
}
cmd_issue_create() {
# issue-create --title <title> [--body <body>] [--assignee <user>] [repo]
# Create an issue. Prints the issue URL on success.
local _title="" _body="" _assignee="" _repo="$HIVE_FORGE_REPO"
while [ $# -gt 0 ]; do
case "$1" in
--title) _title="$2"; shift 2 ;;
--body) _body="$2"; shift 2 ;;
--assignee) _assignee="$2"; shift 2 ;;
*) _repo="$1"; shift ;;
esac
done
if [ -z "$_title" ]; then
echo "usage: hive-forge issue-create --title <title> [--body <body>] [--assignee <user>] [repo]" >&2
exit 1
fi
local _payload
if [ -n "$_assignee" ]; then
_payload=$(jq -n --arg t "$_title" --arg b "$_body" --arg a "$_assignee" \
'{title:$t,body:$b,assignees:[$a]}')
else
_payload=$(jq -n --arg t "$_title" --arg b "$_body" '{title:$t,body:$b}')
fi
forge_post "$FORGE_API/repos/$_repo/issues" "$_payload" \
| jq -r '.html_url'
}
cmd_attach_issue() {
# attach-issue <number> <file> [repo]
# Upload a file as an attachment to an issue. Prints the download URL.
@ -290,8 +347,8 @@ pkgs.writeShellApplication {
VERB="''${1:-}"
if [ -z "$VERB" ]; then
echo "usage: hive-forge <verb> [args...]" >&2
echo "verbs: view, issue, pr, comment, assign, close, labels, pr-reviews," >&2
echo " branches, tree-sha, diff, subscription," >&2
echo "verbs: view, issue, issue-create, issue-edit, pr, pr-create, comment, assign, close," >&2
echo " labels, pr-reviews, branches, tree-sha, diff, subscription," >&2
echo " attach-issue, attach-comment" >&2
exit 1
fi
@ -300,7 +357,9 @@ pkgs.writeShellApplication {
case "$VERB" in
view) cmd_view "$@" ;;
issue) cmd_issue "$@" ;;
issue-create) cmd_issue_create "$@" ;;
pr) cmd_pr "$@" ;;
pr-create) cmd_pr_create "$@" ;;
comment) cmd_comment "$@" ;;
assign) cmd_assign "$@" ;;
close) cmd_close "$@" ;;
@ -314,8 +373,8 @@ pkgs.writeShellApplication {
attach-comment) cmd_attach_comment "$@" ;;
*)
echo "hive-forge: unknown verb '$VERB'" >&2
echo "verbs: view, issue, pr, comment, assign, close, labels, pr-reviews," >&2
echo " branches, tree-sha, diff, subscription," >&2
echo "verbs: view, issue, issue-create, issue-edit, pr, pr-create, comment, assign, close," >&2
echo " labels, pr-reviews, branches, tree-sha, diff, subscription," >&2
echo " attach-issue, attach-comment" >&2
exit 1
;;