84 lines
2.3 KiB
Bash
Executable File
84 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# =============================================================================
|
|
# phase6_teardown.sh — Remove push mirror config from all repos
|
|
# For each repo: fetches mirror ID from Gitea, then deletes it.
|
|
# Re-enables GitHub Actions on the source repos.
|
|
# Safe to run if mirrors have already been removed.
|
|
# =============================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
source "${SCRIPT_DIR}/lib/common.sh"
|
|
|
|
# Parse arguments
|
|
AUTO_YES=false
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--yes|-y) AUTO_YES=true ;;
|
|
--help|-h)
|
|
cat <<EOF
|
|
Usage: $(basename "$0") [options]
|
|
|
|
Options:
|
|
--yes, -y Skip all confirmation prompts
|
|
--help, -h Show this help
|
|
EOF
|
|
exit 0
|
|
;;
|
|
*)
|
|
log_error "Unknown argument: $arg"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
confirm_action() {
|
|
local prompt="$1"
|
|
if [[ "$AUTO_YES" == "true" ]]; then
|
|
log_info "Auto-confirmed (--yes): ${prompt}"
|
|
return 0
|
|
fi
|
|
printf '%s' "$prompt"
|
|
read -r confirm
|
|
[[ "$confirm" =~ ^[Yy]$ ]]
|
|
}
|
|
|
|
load_env
|
|
require_vars GITEA_ADMIN_TOKEN GITEA_INTERNAL_URL GITEA_ORG_NAME \
|
|
GITHUB_USERNAME GITHUB_TOKEN \
|
|
REPO_NAMES
|
|
|
|
log_warn "=== Phase 6 Teardown: Push Mirrors ==="
|
|
|
|
read -ra REPOS <<< "$REPO_NAMES"
|
|
|
|
if ! confirm_action 'This will remove all push mirror configurations. Continue? [y/N] '; then
|
|
log_info "Teardown cancelled"
|
|
exit 0
|
|
fi
|
|
|
|
for repo in "${REPOS[@]}"; do
|
|
log_info "--- Processing: ${repo} ---"
|
|
|
|
# Get push mirror IDs (there could be multiple, delete all)
|
|
MIRRORS=$(gitea_api GET "/repos/${GITEA_ORG_NAME}/${repo}/push_mirrors" 2>/dev/null || echo "[]")
|
|
MIRROR_IDS=$(printf '%s' "$MIRRORS" | jq -r '.[].id' 2>/dev/null || true)
|
|
|
|
if [[ -z "$MIRROR_IDS" ]]; then
|
|
log_info "No push mirrors found for ${repo} — already clean"
|
|
else
|
|
for mirror_id in $MIRROR_IDS; do
|
|
gitea_api DELETE "/repos/${GITEA_ORG_NAME}/${repo}/push_mirrors/${mirror_id}" >/dev/null 2>&1 || true
|
|
log_success "Removed push mirror '${mirror_id}' from ${repo}"
|
|
done
|
|
fi
|
|
|
|
# Re-enable GitHub Actions
|
|
github_api PUT "/repos/${GITHUB_USERNAME}/${repo}/actions/permissions" \
|
|
'{"enabled": true}' >/dev/null 2>&1 || true
|
|
log_info "GitHub Actions re-enabled for ${repo}"
|
|
done
|
|
|
|
log_success "Phase 6 teardown complete"
|