82 lines
2.1 KiB
Markdown
82 lines
2.1 KiB
Markdown
---
|
|
name: gitea
|
|
description: Gitea repository management via REST API. Use when user explicitly mentions "gitea" for: (1) Creating repositories, (2) Listing repositories, (3) Deleting repositories, (4) Pushing code to Gitea. Default server: https://gitea.server10086.icu, default account: admin. Requires GITEA_TOKEN environment variable.
|
|
---
|
|
|
|
# Gitea Repository Management
|
|
|
|
## Configuration
|
|
|
|
- **Server**: `https://gitea.server10086.icu`
|
|
- **API Base**: `https://gitea.server10086.icu/api/v1`
|
|
- **Default Account**: `admin`
|
|
- **Auth Header**: `Authorization: token $GITEA_TOKEN`
|
|
- **Git Remote URL**: `git@gitea.server10086.icu:admin/repo-name.git` (SSH)
|
|
|
|
**Always verify GITEA_TOKEN exists before any operation:**
|
|
```bash
|
|
if [ -z "$GITEA_TOKEN" ]; then
|
|
echo "Error: GITEA_TOKEN environment variable not set"
|
|
exit 1
|
|
fi
|
|
```
|
|
|
|
## Repository Operations
|
|
|
|
### List Repositories
|
|
|
|
```bash
|
|
# List all repos for current user
|
|
curl -s -X GET "https://gitea.server10086.icu/api/v1/user/repos" \
|
|
-H "Authorization: token $GITEA_TOKEN"
|
|
```
|
|
|
|
### Create Repository
|
|
|
|
```bash
|
|
curl -X POST "https://gitea.server10086.icu/api/v1/admin/repos" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"name": "repo-name",
|
|
"description": "Repository description",
|
|
"private": false,
|
|
"auto_init": false
|
|
}'
|
|
```
|
|
|
|
### Delete Repository
|
|
|
|
```bash
|
|
curl -X DELETE "https://gitea.server10086.icu/api/v1/repos/admin/repo-name" \
|
|
-H "Authorization: token $GITEA_TOKEN"
|
|
```
|
|
|
|
### Create and Push Current Directory
|
|
|
|
```bash
|
|
REPO_NAME=$(basename $(pwd))
|
|
|
|
# Create repo via API
|
|
curl -X POST "https://gitea.server10086.icu/api/v1/admin/repos" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"name\":\"$REPO_NAME\",\"auto_init\":false}"
|
|
|
|
# Initialize and push
|
|
git init
|
|
git add .
|
|
git commit -m "Initial commit"
|
|
git remote add origin "git@gitea.server10086.icu:admin/$REPO_NAME.git"
|
|
git push -u origin main
|
|
```
|
|
|
|
## Error Handling
|
|
|
|
| Status | Meaning |
|
|
|--------|---------|
|
|
| 401 | Invalid or missing GITEA_TOKEN |
|
|
| 409 | Repository already exists |
|
|
| 404 | Repository not found |
|
|
| 204 | Successful deletion (expected) |
|