scrum4me-docker/bin/repo-bootstrap.sh
Madhura68 cb8f48d49e feat: switch source URLs from GitHub to Forgejo
Hybride model (PBI-86 in Scrum4Me): de worker clonet en pusht naar
Forgejo (`origin`); GitHub-PR's ontstaan via een handmatige
promote-Action in Forgejo. Variabele-namen blijven `GH_TOKEN` en
`GH_PRECLONE_REPOS` (historisch); inhoud is voortaan een Forgejo-PAT.

- Dockerfile: MCP_GIT_REPO default →
  git.jp-visser.nl/janpeter/scrum4me-mcp.git
- bin/repo-bootstrap.sh: credential-helper host + clone-URL →
  git.jp-visser.nl
- bin/job-prepare.sh: cache-slug comment example bijgewerkt
- .env.example: documentatie + default `GH_PRECLONE_REPOS` naar
  janpeter/Scrum4Me + janpeter/scrum4me-mcp; instructies omgezet naar
  Forgejo-PAT-flow; `gh pr create` (auto_pr) verwijderd uit comment.
- README.md: internet-egress, token-instructies, clone-URL en
  repo-bootstrap-sectie verwijzen nu naar Forgejo. Promote-flow gelinkt.

gh CLI install blijft in Dockerfile staan (no-op zonder gh-aanroepen,
maar weinig kosten om voor ad-hoc gebruik te bewaren).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 17:59:11 +02:00

79 lines
2.9 KiB
Bash

#!/usr/bin/env bash
# repo-bootstrap.sh — pre-clone repos into ~agent/Projects so that
# scrum4me-mcp's `wait_for_job` finds a working repoRoot via the
# convention-fallback `~/Projects/<name>/.git`.
#
# Idempotent:
# - Sets up git credential helper using GH_TOKEN (HTTPS auth)
# - For each entry in GH_PRECLONE_REPOS (comma-separated owner/name list):
# * If ~/Projects/<name> exists → `git fetch origin --prune`
# * Otherwise → fresh `git clone`
#
# Runs as the agent user (called from entrypoint.sh after `gosu agent …`).
set -uo pipefail
source /opt/agent/bin/_lib.sh
: "${GH_TOKEN:=}"
: "${GH_PRECLONE_REPOS:=}"
if [[ -z "$GH_TOKEN" ]]; then
log "GH_TOKEN not set — skipping clone bootstrap. wait_for_job will fail until repos exist."
return 0 2>/dev/null || exit 0
fi
if [[ -z "$GH_PRECLONE_REPOS" ]]; then
log "GH_PRECLONE_REPOS empty — nothing to clone."
return 0 2>/dev/null || exit 0
fi
# ----- 1. configure git credential helper for HTTPS clone/push -----------
mkdir -p "$HOME"
git config --global credential.helper store
CREDS_FILE="$HOME/.git-credentials"
if [[ ! -f "$CREDS_FILE" ]] || ! grep -q "oauth2:${GH_TOKEN}@git.jp-visser.nl" "$CREDS_FILE" 2>/dev/null; then
printf 'https://oauth2:%s@git.jp-visser.nl\n' "$GH_TOKEN" > "$CREDS_FILE"
chmod 600 "$CREDS_FILE"
log "git credentials helper configured at ${CREDS_FILE}"
fi
# Commit-author identity. GIT_AUTHOR_EMAIL MUST be a valid GitHub-linked
# address — Vercel rejects deployments whose latest commit has an
# unknown author email ("commit author email is not valid"). Easiest
# choice: the no-reply form `<id>+<username>@users.noreply.github.com`
# (find it on github.com → Settings → Emails → "Keep my email private").
if [[ -z "${GIT_AUTHOR_EMAIL:-}" ]]; then
log "ERROR: GIT_AUTHOR_EMAIL not set. Vercel will reject deploys whose"
log " commit author email isn't tied to a GitHub account."
log " Use the noreply form, e.g.:"
log " GIT_AUTHOR_EMAIL=12345678+madhura68@users.noreply.github.com"
exit 2
fi
git config --global user.name "${GIT_AUTHOR_NAME:-Scrum4Me Agent}"
git config --global user.email "${GIT_AUTHOR_EMAIL}"
# ----- 2. clone-or-fetch each repo --------------------------------------
mkdir -p "$HOME/Projects"
IFS=',' read -ra REPOS <<< "$GH_PRECLONE_REPOS"
for repo in "${REPOS[@]}"; do
repo=$(echo "$repo" | tr -d '[:space:]')
[[ -z "$repo" ]] && continue
name=$(basename "$repo")
target="$HOME/Projects/$name"
if [[ -d "$target/.git" ]]; then
log "fetching ${repo} into ${target}"
git -C "$target" fetch origin --prune --quiet \
|| log "WARN: fetch failed for ${repo} (continuing)"
else
log "cloning ${repo} into ${target}"
rm -rf "$target"
git clone --quiet "https://git.jp-visser.nl/${repo}.git" "$target" \
|| { log "ERROR: clone failed for ${repo}"; continue; }
fi
done
log "repo-bootstrap done"