#!/usr/bin/env bash # recipe-upgrade :: post a comment on a Gitea PR/issue # ---------------------------------------------------- # Usage: # BODY='text' post-pr-comment.sh # BODY_FILE=/tmp/comment.md post-pr-comment.sh set -o errexit -o nounset -o pipefail REPO="${1:?usage: post-pr-comment.sh }" PRIDX="${2:?usage: post-pr-comment.sh }" TESTENV="${TESTENV:-/srv/cc-ci/.testenv}" set -a; . "$TESTENV"; set +a : "${GITEA_USERNAME:?}" : "${GITEA_PASSWORD:?}" : "${GITEA_URL:?}" if [ -n "${BODY_FILE:-}" ]; then BODY="$(<"${BODY_FILE}")" else : "${BODY:?set BODY or BODY_FILE}" fi API="https://${GITEA_URL}/api/v1" AUTH=(-u "${GITEA_USERNAME}:${GITEA_PASSWORD}") resp="$(mktemp)" code="$({ curl -sS -o "$resp" -w "%{http_code}" "${AUTH[@]}" \ -H "Content-Type: application/json" \ -X POST "${API}/repos/${REPO}/issues/${PRIDX}/comments" \ -d "$(jq -n --arg body "$BODY" '{body:$body}')"; } || true)" if [ "$code" != "201" ]; then echo "ERROR: comment POST failed for ${REPO}#${PRIDX} (HTTP ${code})" >&2 cat "$resp" >&2 || true rm -f "$resp" exit 1 fi jq -r '"COMMENT_URL=" + (.html_url // "") + "\nCOMMENT_ID=" + ((.id // 0) | tostring)' "$resp" rm -f "$resp"