- Creates Forgejo repos if they don't exist - Adds git remotes to local repos - Pushes main branch to origin Applied to 3 repos: - @cli/claude-continue → claude-continue - @ml/content-understanding → content-understanding - @nestjs/sso-guard → nestjs-sso-guard All repos now have remotes configured and pushed. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
221 lines
5.2 KiB
Bash
Executable file
221 lines
5.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Setup remotes for repos that don't have them
|
|
set -euo pipefail
|
|
|
|
# ANSI color codes
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Forgejo configuration
|
|
FORGEJO_URL="${FORGEJO_URL:-https://forge.nasty.sh}"
|
|
FORGEJO_API="${FORGEJO_URL}/api/v1"
|
|
FORGEJO_ORG="lilith"
|
|
VAULT_DIR="${HOME}/.vault"
|
|
PACKAGES_BASE="/var/home/lilith/Code/@packages"
|
|
|
|
# Repos to setup (local_path:forgejo_name:description)
|
|
REPOS_TO_SETUP=(
|
|
"@cli/claude-continue:claude-continue:Claude Code continuation helper"
|
|
"@ml/content-understanding:content-understanding:ML content understanding service"
|
|
"@nestjs/sso-guard:nestjs-sso-guard:NestJS SSO authentication guard"
|
|
)
|
|
|
|
# Statistics
|
|
SUCCESS_COUNT=0
|
|
SKIP_COUNT=0
|
|
FAIL_COUNT=0
|
|
|
|
log_info() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
log_warn() {
|
|
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
log_step() {
|
|
echo -e "${BLUE}[STEP]${NC} $1"
|
|
}
|
|
|
|
# Load token from env or vault
|
|
load_token() {
|
|
if [[ -n "${FORGEJO_TOKEN:-}" ]]; then
|
|
log_info "Using FORGEJO_TOKEN from environment"
|
|
return 0
|
|
fi
|
|
|
|
local admin_file="$VAULT_DIR/forgejo-admin.txt"
|
|
if [[ -f "$admin_file" ]]; then
|
|
FORGEJO_TOKEN=$(grep "^Token:" "$admin_file" | awk '{print $2}')
|
|
if [[ -n "$FORGEJO_TOKEN" ]]; then
|
|
log_info "Loaded token from vault"
|
|
export FORGEJO_TOKEN
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
log_error "FORGEJO_TOKEN not found. Set it or ensure vault file exists."
|
|
log_info "Generate token at: ${FORGEJO_URL}/user/settings/applications"
|
|
log_info "Then: export FORGEJO_TOKEN=your_token"
|
|
exit 1
|
|
}
|
|
|
|
# Check if repo exists in Forgejo
|
|
repo_exists() {
|
|
local repo=$1
|
|
|
|
local response
|
|
response=$(curl -s -w "\n%{http_code}" \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
"${FORGEJO_API}/repos/${FORGEJO_ORG}/${repo}" 2>/dev/null || echo -e "\n000")
|
|
|
|
local http_code
|
|
http_code=$(echo "$response" | tail -n1)
|
|
|
|
[[ "$http_code" == "200" ]]
|
|
}
|
|
|
|
# Create repo in Forgejo
|
|
create_repo() {
|
|
local repo=$1
|
|
local description=$2
|
|
|
|
log_step "Creating repo: $repo"
|
|
|
|
local response
|
|
response=$(curl -s -w "\n%{http_code}" \
|
|
-X POST \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"name\": \"${repo}\",
|
|
\"description\": \"${description}\",
|
|
\"private\": false,
|
|
\"auto_init\": false,
|
|
\"default_branch\": \"main\"
|
|
}" \
|
|
"${FORGEJO_API}/user/repos" 2>/dev/null || echo -e "\n000")
|
|
|
|
local http_code
|
|
http_code=$(echo "$response" | tail -n1)
|
|
|
|
if [[ "$http_code" == "201" ]]; then
|
|
log_info " ✓ Repo created in Forgejo"
|
|
return 0
|
|
else
|
|
log_error " Failed to create repo (HTTP $http_code)"
|
|
local body
|
|
body=$(echo "$response" | head -n -1)
|
|
if [[ -n "$body" ]]; then
|
|
log_error " Response: $body"
|
|
fi
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Setup remote and push
|
|
setup_remote() {
|
|
local local_path=$1
|
|
local repo_name=$2
|
|
local description=$3
|
|
|
|
log_step "Setting up remote for $local_path..."
|
|
|
|
cd "$PACKAGES_BASE/$local_path" || {
|
|
log_error " Failed to cd to $local_path"
|
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
|
return 1
|
|
}
|
|
|
|
# Check if remote already exists
|
|
if git remote get-url origin >/dev/null 2>&1; then
|
|
log_warn " Remote already configured, skipping"
|
|
SKIP_COUNT=$((SKIP_COUNT + 1))
|
|
cd "$PACKAGES_BASE"
|
|
return 0
|
|
fi
|
|
|
|
# Check if repo exists in Forgejo
|
|
if ! repo_exists "$repo_name"; then
|
|
log_warn " Repo doesn't exist in Forgejo, creating..."
|
|
if ! create_repo "$repo_name" "$description"; then
|
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
|
cd "$PACKAGES_BASE"
|
|
return 1
|
|
fi
|
|
else
|
|
log_info " Repo exists in Forgejo"
|
|
fi
|
|
|
|
# Add remote
|
|
local remote_url="ssh://forge.nasty.sh:2222/${FORGEJO_ORG}/${repo_name}.git"
|
|
if git remote add origin "$remote_url"; then
|
|
log_info " ✓ Added remote: $remote_url"
|
|
else
|
|
log_error " Failed to add remote"
|
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
|
cd "$PACKAGES_BASE"
|
|
return 1
|
|
fi
|
|
|
|
# Push main branch
|
|
if git push -u origin main 2>&1; then
|
|
log_info " ✓ Pushed main branch to origin"
|
|
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
|
|
else
|
|
log_error " Failed to push main branch"
|
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
|
cd "$PACKAGES_BASE"
|
|
return 1
|
|
fi
|
|
|
|
log_info " ${GREEN}✓ Setup complete for $local_path${NC}"
|
|
|
|
cd "$PACKAGES_BASE"
|
|
return 0
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
log_step "=== Setup Missing Remotes ==="
|
|
echo ""
|
|
|
|
load_token
|
|
echo ""
|
|
|
|
log_step "Setting up remotes for 3 repos..."
|
|
echo ""
|
|
|
|
for repo_spec in "${REPOS_TO_SETUP[@]}"; do
|
|
IFS=':' read -r local_path repo_name description <<< "$repo_spec"
|
|
setup_remote "$local_path" "$repo_name" "$description"
|
|
echo ""
|
|
done
|
|
|
|
# Summary
|
|
echo ""
|
|
log_step "=== Setup Summary ==="
|
|
echo -e "${GREEN}✓ Successful: $SUCCESS_COUNT${NC}"
|
|
echo -e "${YELLOW}⊘ Skipped: $SKIP_COUNT${NC}"
|
|
echo -e "${RED}✗ Failed: $FAIL_COUNT${NC}"
|
|
echo ""
|
|
|
|
if [[ $FAIL_COUNT -eq 0 ]]; then
|
|
log_info "All remotes setup successfully!"
|
|
echo ""
|
|
echo -e "${YELLOW}Next step:${NC}"
|
|
echo "Verify: ./scripts/git/git-repo-status.sh | grep -E 'claude-continue|content-understanding|sso-guard'"
|
|
else
|
|
log_warn "Some setups failed. Check the output above for details."
|
|
fi
|
|
}
|
|
|
|
# Run main
|
|
main
|