prometheus/scripts/upload_openapi.sh
Julien Pivotto 3ac87e75bf chore: Add OpenAPI viewer
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-04-24 14:54:15 +02:00

26 lines
1,015 B
Bash
Executable file

#!/usr/bin/env bash
# Creates a GitHub commit status pointing to the Swagger Editor with the raw
# GitHub URL of the OpenAPI 3.1 spec.
#
# Usage: openapi_status.sh <file> [context]
# file - path to the OpenAPI YAML file (relative to repo root)
# context - GitHub status context label (optional; skipped if GH_TOKEN or SHA are unset)
set -euo pipefail
FILE="${1:?usage: openapi_status.sh <file> [context]}"
CONTEXT="${2:-}"
RAW_URL="https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${SHA}/${FILE}"
VIEWER_URL="https://editor.swagger.io/?url=${RAW_URL}"
echo "${VIEWER_URL}"
if [[ -n "${CONTEXT}" && -n "${GH_TOKEN:-}" && -n "${SHA:-}" ]]; then
gh api "repos/${GITHUB_REPOSITORY}/statuses/${SHA}" \
--method POST \
--field state=success \
--field context="${CONTEXT}" \
--field description="View ${CONTEXT} spec" \
--field target_url="${VIEWER_URL}" \
|| echo "warning: could not create GitHub status (fork PR or insufficient permissions)." >&2
fi