feat(recipe-upgrade): add stale-test PR helpers
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
# recipe-upgrade :: post a comment on a Gitea PR/issue
|
||||
# ----------------------------------------------------
|
||||
# Usage:
|
||||
# BODY='text' post-pr-comment.sh <owner/repo> <pr-number>
|
||||
# BODY_FILE=/tmp/comment.md post-pr-comment.sh <owner/repo> <pr-number>
|
||||
set -o errexit -o nounset -o pipefail
|
||||
|
||||
REPO="${1:?usage: post-pr-comment.sh <owner/repo> <pr-number>}"
|
||||
PRIDX="${2:?usage: post-pr-comment.sh <owner/repo> <pr-number>}"
|
||||
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"
|
||||
Reference in New Issue
Block a user