Update: Add auto-create repository feature to summary agent

- Agent now supports GITEA_API_TOKEN environment variable
- Automatically creates Gitea repos for new VPS projects
- Includes setup guide for generating and storing API tokens
- Falls back gracefully if token not available
- Reduces manual repo creation steps on new VPS instances
This commit is contained in:
root
2025-11-23 21:11:33 +00:00
parent f2f84b3a24
commit a2c098805f

View File

@@ -122,9 +122,9 @@ Add new timestamped entry:
**Important:** Only CLAUDE.md should be updated by default. **Important:** Only CLAUDE.md should be updated by default.
### Step 5: Ensure Git Remote Metadata (Gitea-Optimized) ### Step 5: Ensure Git Remote & Auto-Create Repository (Gitea-Optimized)
Handle Git remote configuration for Gitea: Handle Git remote configuration and auto-create Gitea repository if needed:
#### Detect Repository Type: #### Detect Repository Type:
```bash ```bash
@@ -132,10 +132,36 @@ Handle Git remote configuration for Gitea:
if [[ "$PWD" == *"homelab-agents"* ]]; then if [[ "$PWD" == *"homelab-agents"* ]]; then
REPO_TYPE="homelab-agents" REPO_TYPE="homelab-agents"
REPO_URL="http://100.120.125.113:3000/pdm/homelab-agents.git" REPO_URL="http://100.120.125.113:3000/pdm/homelab-agents.git"
REPO_NAME="homelab-agents"
else else
REPO_TYPE="vps-project" REPO_TYPE="vps-project"
PROJECT_NAME=$(basename "$PWD") PROJECT_NAME=$(basename "$PWD")
REPO_URL="http://100.120.125.113:3000/pdm/$PROJECT_NAME.git" REPO_URL="http://100.120.125.113:3000/pdm/$PROJECT_NAME.git"
REPO_NAME="$PROJECT_NAME"
fi
```
#### Auto-Create Repository if Missing (Optional - Requires API Token):
```bash
GITEA_URL="http://100.120.125.113:3000"
GITEA_TOKEN="${GITEA_API_TOKEN:-}"
if [[ -n "$GITEA_TOKEN" && "$REPO_TYPE" == "vps-project" ]]; then
# Check if repo exists by trying to access it
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$GITEA_URL/api/v1/repos/pdm/$REPO_NAME")
if [[ "$HTTP_STATUS" == "404" ]]; then
echo "📦 Creating repository on Gitea: $REPO_NAME"
curl -s -X POST "$GITEA_URL/api/v1/user/repos" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"name\": \"$REPO_NAME\", \"description\": \"VPS Project: $REPO_NAME\", \"private\": false}" \
> /dev/null
echo "✅ Repository created successfully"
fi
elif [[ -z "$GITEA_TOKEN" && "$REPO_TYPE" == "vps-project" ]]; then
echo "⚠️ Optional: Set GITEA_API_TOKEN for automatic repo creation"
echo " Without it, you must create the repo manually in Gitea web UI first"
fi fi
``` ```
@@ -157,7 +183,7 @@ fi
git remote -v git remote -v
echo "GITEA_URL=http://100.120.125.113:3000" > .gitconfig.local echo "GITEA_URL=http://100.120.125.113:3000" > .gitconfig.local
echo "REPOSITORY_TYPE=$REPO_TYPE" >> .gitconfig.local echo "REPOSITORY_TYPE=$REPO_TYPE" >> .gitconfig.local
echo "REPOSITORY_PATH=pdm/$PROJECT_NAME.git" >> .gitconfig.local echo "REPOSITORY_PATH=pdm/$REPO_NAME.git" >> .gitconfig.local
git add .gitconfig.local git add .gitconfig.local
``` ```
@@ -287,8 +313,9 @@ Before declaring a session closed, verify:
- Include all sections for future context resumption - Include all sections for future context resumption
**Gitea repository doesn't exist yet:** **Gitea repository doesn't exist yet:**
- Create through Gitea web UI at http://100.120.125.113:3000 - **Auto-Create (Recommended)**: Set `GITEA_API_TOKEN` environment variable and the agent will create it automatically
- Then configure git remote - **Manual Creation**: Create through Gitea web UI at http://100.120.125.113:3000, then configure git remote
- See "Setting Up API Token for Auto-Repository Creation" section below
**Network access to Gitea unavailable:** **Network access to Gitea unavailable:**
- Commit changes locally - Commit changes locally
@@ -297,6 +324,49 @@ Before declaring a session closed, verify:
--- ---
## Setting Up API Token for Auto-Repository Creation
To enable automatic Gitea repository creation on new VPS projects, follow these steps once:
### Step 1: Generate API Token on Gitea Server
Log in to Gitea web UI (http://100.120.125.113:3000) as user `pdm`:
1. Go to Settings → Applications → Personal Access Tokens
2. Click "Generate Token"
3. Name it: `vps-automation`
4. Select scope: `repo` (for creating repositories)
5. Click "Generate Token"
6. Copy the token (you'll only see it once)
### Step 2: Store Token on VPS
On each VPS where you'll create new projects, save the token:
```bash
# Option A: Add to ~/.bashrc for all sessions
echo 'export GITEA_API_TOKEN="your-token-here"' >> ~/.bashrc
source ~/.bashrc
# Option B: Store in a secure file and source it
mkdir -p ~/.homelab-secrets
echo 'export GITEA_API_TOKEN="your-token-here"' > ~/.homelab-secrets/gitea-token.sh
chmod 600 ~/.homelab-secrets/gitea-token.sh
echo 'source ~/.homelab-secrets/gitea-token.sh 2>/dev/null' >> ~/.bashrc
```
### Step 3: Use with Summary Agent
Once set up, the agent will automatically:
1. Detect when you're in a new project directory (not homelab-agents)
2. Check if the Gitea repository exists
3. Create it if missing using the API token
4. Configure the git remote
5. Push your work
No manual repository creation needed!
---
## Implementation Notes ## Implementation Notes
This agent works seamlessly with your Gitea instance at **http://100.120.125.113:3000** (user: pdm). This agent works seamlessly with your Gitea instance at **http://100.120.125.113:3000** (user: pdm).
@@ -306,4 +376,4 @@ This agent works seamlessly with your Gitea instance at **http://100.120.125.113
- `http://100.120.125.113:3000/pdm/vps-system-apps.git` - VPS apps config - `http://100.120.125.113:3000/pdm/vps-system-apps.git` - VPS apps config
- `http://100.120.125.113:3000/pdm/[any-project-name].git` - Future projects - `http://100.120.125.113:3000/pdm/[any-project-name].git` - Future projects
The agent automatically detects your Gitea server and configures repositories appropriately, ensuring project continuity across all homelab work sessions. The agent automatically detects your Gitea server and configures repositories appropriately, ensuring project continuity across all homelab work sessions.