Files
MokoCLI/scripts/sync-wikis-to-github.sh
T
Jonathan Miller 5e894a2c8f feat: add wiki health check and GitHub wiki mirror sync
- validate/check_wiki_health.php — checks Home page, MokoStandards ref
- scripts/sync-wikis-to-github.sh — mirrors Gitea wikis to GitHub
- MCP tools: standards_check_wiki, standards_sync_wikis

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-09 17:58:20 -05:00

97 lines
3.1 KiB
Bash

#!/usr/bin/env bash
# sync-wikis-to-github.sh — Mirror Gitea wiki repos to their GitHub counterparts
#
# Clones each Gitea wiki repo, adds the GitHub wiki as a remote, and force-pushes.
# Requires GH_TOKEN env var or ~/.github-token for authentication.
#
# Usage:
# sync-wikis-to-github.sh [repo-name] # sync one repo
# sync-wikis-to-github.sh # sync all configured repos
#
# Requires: git, curl
#
set -euo pipefail
GITEA_URL="${GITEA_URL:-https://git.mokoconsulting.tech}"
GITHUB_ORG="${GITHUB_ORG:-mokoconsulting-tech}"
GH_TOKEN="${GH_TOKEN:-$(cat ~/.github-token 2>/dev/null || echo "")}"
GITEA_TOKEN="${GITEA_TOKEN:-$(cat ~/.gitea-token 2>/dev/null || echo "")}"
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
log() { echo "[$(date '+%H:%M:%S')] $*"; }
if [[ -z "$GH_TOKEN" ]]; then
log "ERROR: GH_TOKEN not set. Export it or create ~/.github-token"
exit 1
fi
# Repo mappings: gitea_owner/repo → github_repo (same name unless overridden)
declare -A REPOS=(
["MokoConsulting/moko-platform"]="moko-platform"
["MokoConsulting/MokoOnyx"]="MokoOnyx"
["MokoConsulting/MokoWaaS"]="MokoWaaS"
["MokoConsulting/monitor-mcp"]="monitor-mcp"
["MokoConsulting/deploy-mcp"]="deploy-mcp"
["MokoConsulting/ssh-mcp"]="ssh-mcp"
["MokoConsulting/backup-mcp"]="backup-mcp"
["MokoConsulting/joomla-api-mcp"]="joomla-api-mcp"
["MokoConsulting/Template-Client-WaaS"]="Template-Client-WaaS"
["ClarksvilleFurs/client-waas-clarksvillefurs"]="client-waas-clarksvillefurs"
)
FILTER="${1:-}"
SYNCED=0
FAILED=0
for GITEA_REPO in "${!REPOS[@]}"; do
GH_REPO="${REPOS[$GITEA_REPO]}"
# Filter to specific repo if requested
if [[ -n "$FILTER" && "$GH_REPO" != "$FILTER" && "$GITEA_REPO" != *"$FILTER"* ]]; then
continue
fi
log "Syncing wiki: ${GITEA_REPO} → github/${GH_REPO}"
WORK="${TMPDIR}/${GH_REPO}.wiki"
# Clone Gitea wiki
GITEA_WIKI_URL="${GITEA_URL}/${GITEA_REPO}.wiki.git"
if ! git clone --quiet "$GITEA_WIKI_URL" "$WORK" 2>/dev/null; then
log " SKIP: no wiki on Gitea"
continue
fi
cd "$WORK"
# Add GitHub wiki remote
GH_WIKI_URL="https://${GH_TOKEN}@github.com/${GITHUB_ORG}/${GH_REPO}.wiki.git"
# Ensure GitHub wiki exists (create initial page if needed)
WIKI_CHECK=$(curl -sf -H "Authorization: token ${GH_TOKEN}" \
"https://api.github.com/repos/${GITHUB_ORG}/${GH_REPO}" 2>/dev/null | \
python3 -c "import sys,json; print(json.load(sys.stdin).get('has_wiki', False))" 2>/dev/null || echo "False")
if [[ "$WIKI_CHECK" != "True" ]]; then
log " SKIP: GitHub wiki not enabled for ${GH_REPO}"
FAILED=$((FAILED + 1))
continue
fi
git remote add github "$GH_WIKI_URL" 2>/dev/null || git remote set-url github "$GH_WIKI_URL"
# Force push to GitHub wiki
if git push --force --quiet github master:master 2>/dev/null || git push --force --quiet github main:master 2>/dev/null; then
SYNCED=$((SYNCED + 1))
log " OK: synced"
else
FAILED=$((FAILED + 1))
log " FAIL: push failed"
fi
cd "$TMPDIR"
done
log "Done. Synced: ${SYNCED}, Failed: ${FAILED}"