diff --git a/skills/kugetsu/scripts/kugetsu b/skills/kugetsu/scripts/kugetsu index 24152c1..9ad0637 100755 --- a/skills/kugetsu/scripts/kugetsu +++ b/skills/kugetsu/scripts/kugetsu @@ -544,6 +544,47 @@ cmd_logs() { done } +cmd_post_comment() { + local repo_url="${1:-}" + local issue_or_pr="${2:-}" + local body="${3:-}" + + if [ -z "$repo_url" ] || [ -z "$issue_or_pr" ] || [ -z "$body" ]; then + echo "Usage: kugetsu post-comment " >&2 + echo "Example: kugetsu post-comment https://git.fbrns.co/shoko/kugetsu 81 \"Comment text\"" >&2 + exit 1 + fi + + local token="${GITEA_TOKEN:-}" + if [ -z "$token" ]; then + if [ -f "$KUGETSU_DIR/env/pm-agent.env" ]; then + set -a + source "$KUGETSU_DIR/env/pm-agent.env" + set +a + fi + token="${GITEA_TOKEN:-}" + fi + + if [ -z "$token" ]; then + echo "Error: GITEA_TOKEN not set" >&2 + exit 1 + fi + + local api_url="${repo_url%.git}/issues/${issue_or_pr}/comments" + + curl -s -X POST "$api_url" \ + -H "Authorization: token $token" \ + -H "Content-Type: application/json" \ + -d "$(printf '{"body":%s}' "$(echo "$body" | python3 -c 'import sys,json; print(json.dumps(sys.stdin.read()))')")" + + if [ $? -eq 0 ]; then + echo "Comment posted successfully" + else + echo "Error: Failed to post comment" >&2 + exit 1 + fi +} + cmd_doctor() { local fix=false @@ -1180,6 +1221,9 @@ main() { notify) cmd_notify "$@" ;; + post-comment) + cmd_post_comment "$@" + ;; list) cmd_list "$@" ;;