#!/usr/bin/env bash # Promote a coulomb repo to Forgejo (tier 2.5): mirror, flip remotes, add ci-smoke. set -euo pipefail REPO="${1:?usage: promote-repo-to-forgejo.sh [repo-path]}" REPO_PATH="${2:-$HOME/${REPO}}" ORG=coulomb FORGEJO_API="${FORGEJO_API:-https://forgejo.coulomb.social/api/v1}" TOKEN_FILE="${FORGEJO_TOKEN_FILE:-/tmp/forgejo-tegwick-api-token}" TEMPLATE="${PROMOTE_CI_TEMPLATE:-$HOME/railiance-enablement/workflows/ci-smoke.yaml}" if [[ ! -f "${TOKEN_FILE}" ]]; then echo "Missing API token at ${TOKEN_FILE}" >&2 exit 1 fi TOKEN=$(cat "${TOKEN_FILE}") AUTH=(-H "Authorization: token ${TOKEN}") code=$(curl -sS -o /dev/null -w '%{http_code}' "${AUTH[@]}" "${FORGEJO_API}/repos/${ORG}/${REPO}") if [[ "${code}" == "404" ]]; then echo "==> Creating ${ORG}/${REPO} on Forgejo" curl -fsS -X POST "${FORGEJO_API}/orgs/${ORG}/repos" "${AUTH[@]}" \ -H "Content-Type: application/json" \ -d "{\"name\":\"${REPO}\",\"private\":false,\"auto_init\":false}" >/dev/null elif [[ "${code}" == "200" ]]; then echo "==> ${ORG}/${REPO} already exists on Forgejo" else echo "Unexpected API status ${code} for ${ORG}/${REPO}" >&2 exit 1 fi cd "${REPO_PATH}" mkdir -p .forgejo/workflows if [[ ! -f .forgejo/workflows/ci-smoke.yaml ]]; then cp "${TEMPLATE}" .forgejo/workflows/ci-smoke.yaml git add .forgejo/workflows/ci-smoke.yaml git commit --no-verify -m "Add Forgejo CI smoke workflow (enablement template)" fi if git remote get-url origin 2>/dev/null | grep -q forgejo-remote; then echo "==> Remotes already on Forgejo" else git remote rename origin gitea git remote add origin "forgejo-remote:${ORG}/${REPO}.git" echo "==> Remotes: origin=forgejo-remote, gitea=legacy" fi echo "==> Pushing ${REPO_PATH} to Forgejo" git push -u origin main echo "==> Promoted ${REPO}"