#!/usr/bin/env bash # Stop repository admins from overriding the merge requirements on `main`. # # WHY. Gitea lets repo admins override branch-protection merge requirements unless # `block_admin_merge_override` is set. It was FALSE, and jakman85 holds `owner` -- so # required_approvals and the required status check were both overridable by the one account # that actually merges. Evidence: PRs #5-#9 all merged with ZERO approvals recorded against # `required_approvals: 1`. # # NOTE ON FIELD NAMES: this Gitea (1.24.3) has NO `apply_to_admins` field. Querying it with jq # returns null, which reads like "set to false" but actually means "key absent". Enumerate the # real keys (`to_entries`) rather than probing names you assume exist. # # Recoverable: an owner can PATCH this back to false if it gets in the way. set -euo pipefail HOST=gitea.home.keithjackson.dev; OWNER=Home-Network; REPO=home-network-k3s-impl creds="$(printf 'protocol=https\nhost=%s\n\n' "$HOST" | git credential fill)" U="$(sed -n 's/^username=//p' <<<"$creds")"; P="$(sed -n 's/^password=//p' <<<"$creds")" api() { curl -sS --config <(printf 'user = "%s:%s"\n' "$U" "$P") "$@"; } B="https://${HOST}/api/v1/repos/${OWNER}/${REPO}/branch_protections/main" echo "==> before: block_admin_merge_override = $(api "$B" | jq -r .block_admin_merge_override)" api -X PATCH -H 'Content-Type: application/json' \ -d '{"block_admin_merge_override": true}' "$B" >/dev/null AFTER=$(api "$B" | jq -r .block_admin_merge_override) echo "==> after: block_admin_merge_override = $AFTER" [ "$AFTER" = true ] || { echo "PATCH did not take -- do not record this as enforced." >&2; exit 1; } api "$B" | jq -r '{enable_push,enable_status_check,status_check_contexts,required_approvals,block_admin_merge_override}' cat <<'NOTE' NOW PROVE IT -- the setting is not the evidence. On the next PR: * let the gate go green, then try to merge WITHOUT approving it. * Gitea must REFUSE. If it merges, this still is not doing its job. Do not record approvals as enforced until you have seen a merge refused. NOTE