#!/usr/bin/env bash # ci-stats.sh — Gitea Actions run statistics (failure watch + duration trend). # Run from ts, tn, or any host with the SSH tunnel to Gitea API. # Requires: curl, jq, and a Gitea token with read:repository on est org. set -eu GITEA_BASE="${GITEA_BASE:-http://127.0.0.1:3300/api/v1}" GITEA_TOKEN="${GITEA_TOKEN:?set GITEA_TOKEN (read:repository on est)}" REPOS="${REPOS:?set REPOS (space-separated repo names under the org)}" LIMIT="${LIMIT:-10}" for repo in $REPOS; do echo "=== est/$repo (latest $LIMIT) ===" curl -s --max-time 20 -H "Authorization: token $GITEA_TOKEN" \ "$GITEA_BASE/repos/est/$repo/actions/tasks?limit=$LIMIT" \ | jq -r '.workflow_runs[] | (.updated_at | fromdateiso8601) as $up | (.created_at | fromdateiso8601) as $cr | [.run_number, .name, .status, (($up - $cr) | tostring + "s"), .display_title] | @tsv' \ | awk -F'\t' '{printf " %-6s %-14s %-9s %-8s %s\n", $1, $2, $3, $4, $5}' echo " summary:" curl -s --max-time 20 -H "Authorization: token $GITEA_TOKEN" \ "$GITEA_BASE/repos/est/$repo/actions/tasks?limit=100" \ | jq -r '[.workflow_runs[]?.status] | group_by(.) | map("\(.[0]): \(length)") | .[]' \ | sed 's/^/ /' done