Some checks failed
CI / test-and-build (push) Failing after 25s
Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.9 KiB
Bash
52 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
|
# Create empty org/user repo "games_app" on local Gitea via API (admin basic auth).
|
|
set -euo pipefail
|
|
ROOT="$(cd "$(dirname "$0")" && pwd)"
|
|
cd "$ROOT"
|
|
set -a; source .env; set +a
|
|
|
|
BASE="http://127.0.0.1:${GITEA_HTTP_PORT:-3000}"
|
|
USER="${GITEA_ADMIN_USER}"
|
|
PASS="${GITEA_ADMIN_PASSWORD}"
|
|
REPO="${GITEA_REPO_NAME:-games_app}"
|
|
|
|
echo "Creating repository $USER/$REPO (ignore if exists)..."
|
|
code="$(curl -s -o /tmp/gitea-repo.json -w '%{http_code}' -u "${USER}:${PASS}" \
|
|
-H 'Content-Type: application/json' \
|
|
-d "{\"name\":\"${REPO}\",\"private\":true,\"auto_init\":false,\"default_branch\":\"main\",\"description\":\"Tloto monorepo\"}" \
|
|
"${BASE}/api/v1/user/repos")"
|
|
|
|
if [[ "$code" == "201" ]]; then
|
|
echo "REPO_CREATED"
|
|
elif [[ "$code" == "409" ]] || grep -qi 'already exist' /tmp/gitea-repo.json 2>/dev/null; then
|
|
echo "REPO_EXISTS"
|
|
else
|
|
echo "HTTP $code"; cat /tmp/gitea-repo.json; exit 1
|
|
fi
|
|
|
|
# Create access token for git push (stored once)
|
|
TOKEN_NAME="windows-push-$(date +%Y%m%d)"
|
|
TOKEN="$(curl -fsS -u "${USER}:${PASS}" -H 'Content-Type: application/json' \
|
|
-d "{\"name\":\"${TOKEN_NAME}\",\"scopes\":[\"write:repository\",\"write:issue\",\"write:package\",\"read:user\"]}" \
|
|
"${BASE}/api/v1/users/${USER}/tokens" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("sha1",""))')"
|
|
|
|
OUT="$HOME/gitea-push-credentials.txt"
|
|
cat > "$OUT" <<EOF
|
|
Gitea clone (HTTPS):
|
|
http://191.215.41.53:3000/${USER}/${REPO}.git
|
|
|
|
Admin user: ${USER}
|
|
Push token (store in Windows credential manager / Gitea secret, not in git):
|
|
${TOKEN}
|
|
|
|
From Windows (PowerShell), in your local games_app repo:
|
|
git remote remove gitea 2>\$null
|
|
git remote add gitea http://tloto-admin:${TOKEN}@191.215.41.53:3000/${USER}/${REPO}.git
|
|
git push -u gitea HEAD:main
|
|
|
|
Then remove the token from the remote URL and use a credential helper:
|
|
git remote set-url gitea http://191.215.41.53:3000/${USER}/${REPO}.git
|
|
EOF
|
|
chmod 600 "$OUT"
|
|
echo "Wrote $OUT"
|