feat(scripts): implement report-status.sh with bats and cucumber tests (#1)
CI — gitea-ci-library / feature (push) Failing after 0s
CI — gitea-ci-library / master (push) Has been skipped

Co-authored-by: moilanik <niko.moilanen@tietoevry.com>
Reviewed-on: #1
This commit is contained in:
2026-06-08 11:33:09 +03:00
parent 9a59cbc185
commit 1379bbf1ee
13 changed files with 1746 additions and 6 deletions
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
[ -z "${GITEA_API_URL:-}" ] && echo "ERROR: GITEA_API_URL is not set" >&2 && exit 1
[ -z "${GITEA_TOKEN:-}" ] && echo "ERROR: GITEA_TOKEN is not set" >&2 && exit 1
STATE="${1:-}"
DESCRIPTION="${2:-}"
URL="${3:-}"
KEY="${4:-commit-${GITHUB_SHA:0:8}}"
ROOT_COMMIT="${5:-}"
ROOT_REPO="${6:-}"
[ -z "$STATE" ] && echo "ERROR: state argument is required" >&2 && exit 1
[ -z "$DESCRIPTION" ] && echo "ERROR: description argument is required" >&2 && exit 1
[ -z "$URL" ] && echo "ERROR: url argument is required" >&2 && exit 1
if [ -n "$ROOT_COMMIT" ] && [ -n "$ROOT_REPO" ]; then
REPO="$ROOT_REPO"
COMMIT="$ROOT_COMMIT"
else
REPO="${GITHUB_REPOSITORY:-}"
COMMIT="${GITHUB_SHA:-}"
fi
[ -z "$REPO" ] && echo "ERROR: GITHUB_REPOSITORY is not set" >&2 && exit 1
[ -z "$COMMIT" ] && echo "ERROR: GITHUB_SHA is not set" >&2 && exit 1
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST "$GITEA_API_URL/api/v1/repos/$REPO/statuses/$COMMIT" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"state\":\"$STATE\",\"target_url\":\"$URL\",\"description\":\"$DESCRIPTION\",\"context\":\"$KEY\"}")
if [ "$HTTP_CODE" = "201" ]; then
exit 0
fi
if [ -z "$HTTP_CODE" ]; then
echo "ERROR: Failed to connect to Gitea API at $GITEA_API_URL" >&2
else
echo "ERROR: API returned HTTP $HTTP_CODE" >&2
fi
exit 1