Files
opencode/command/gitea-reset.md
Voson 5a05d5ab53 chore: 重构 OpenCode 命令和技能文档体系
- 新增:统一的 git 命令文档(add/commit/push/pull 等)
- 新增:整合的 Gitea 技能文档(API、运行器、工作流等)
- 新增:工作流模板(Android、Go、Node.js 等)
- 移除:已弃用的旧命令脚本和发布脚本
- 改进:.gitignore 添加敏感文件保护规则
- 改进:AGENTS.md 完善了开发规范和示例

此次重组统一了命令和技能的文档结构,便于后续维护和扩展。
2026-01-13 00:27:21 +08:00

315 lines
7.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: Reset Gitea configuration with interactive setup wizard
---
# gitea-reset
重置 Gitea 配置,启动交互式配置向导。
## Features
- 交互式引导配置
- 验证 URL 和 Token
- 检查 Token 权限
- 自动保存配置到 `~/.config/gitea/config.env`
- 创建必要的目录结构
## Steps
### 1. Create Configuration Directory
```bash
config_dir="$HOME/.config/gitea"
config_file="$config_dir/config.env"
# Create directories
mkdir -p "$config_dir/runners"
echo "开始 Gitea 配置向导..."
echo ""
```
### 2. Input Gitea URL
```bash
read -p "请输入 Gitea 实例地址 (例如: https://git.digitevents.com): " gitea_url
# Validate URL format
if ! [[ "$gitea_url" =~ ^https?:// ]]; then
echo "❌ URL 必须以 http:// 或 https:// 开头"
exit 1
fi
# Remove trailing slash
gitea_url="${gitea_url%/}"
echo "✓ URL: $gitea_url"
```
### 3. Input Personal Access Token
```bash
echo ""
read -sp "请输入 Personal Access Token: " gitea_token
echo ""
if [ -z "$gitea_token" ]; then
echo "❌ Token 不能为空"
exit 1
fi
echo "✓ Token 已输入"
```
**Token 获取提示**
在用户输入 Token 前,可以显示帮助信息:
```
提示:获取 Personal Access Token 的步骤:
1. 登录 Gitea
2. 右上角头像 → 设置 → 应用 → 访问令牌
3. 点击 "生成新令牌"
4. 设置令牌名称(如 opencode-cli
5. 选择权限repo, admin:org, write:runner推荐
6. 点击 "生成令牌"
7. 复制生成的 Token
```
### 4. Test Connection
```bash
echo ""
echo "正在测试连接..."
response=$(curl -s -w "\n%{http_code}" \
-H "Authorization: token $gitea_token" \
"${gitea_url}/api/v1/user")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" != "200" ]; then
echo "❌ 连接失败 (HTTP $http_code)"
echo "请检查:"
echo " - URL 是否正确"
echo " - Token 是否有效"
echo " - 网络连接是否正常"
exit 1
fi
username=$(echo "$body" | jq -r '.login')
echo "✓ 连接成功!"
echo "✓ 登录用户: $username"
```
### 5. Validate Token Permissions
```bash
echo ""
echo "正在检查 Token 权限..."
# Check repo permission
if curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token $gitea_token" \
"${gitea_url}/api/v1/user/repos" | grep -q "200"; then
echo " ✓ repo (仓库管理)"
has_repo=true
else
echo " ✗ repo (仓库管理) - 缺少"
has_repo=false
fi
# Check org permission
if curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token $gitea_token" \
"${gitea_url}/api/v1/user/orgs" | grep -q "200"; then
echo " ✓ admin:org (组织管理)"
has_org=true
else
echo " ⚠ admin:org (组织管理) - 缺少(创建组织 Runner 时需要)"
has_org=false
fi
# Check runner permission (try to get a registration token)
if curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token $gitea_token" \
"${gitea_url}/api/v1/user/actions/runners/registration-token" 2>/dev/null | grep -q "200"; then
echo " ✓ write:runner (Runner 管理)"
has_runner=true
else
echo " ⚠ write:runner (Runner 管理) - 缺少(创建 Runner 时需要)"
has_runner=false
fi
# Warning if missing critical permissions
if [ "$has_repo" = false ]; then
echo ""
echo "❌ 缺少必需的 repo 权限"
read -p "是否继续? [y/N] " continue_anyway
if [[ ! "$continue_anyway" =~ ^[Yy]$ ]]; then
echo "已取消,请重新创建具有足够权限的 Token"
exit 1
fi
fi
```
### 6. Input Default Organization (Optional)
```bash
echo ""
echo "设置默认组织(可选):"
echo " - 创建仓库时,如果不指定 owner将使用默认组织"
echo " - 创建组织级 Runner 时使用"
echo ""
read -p "请输入默认组织名称 (回车跳过): " default_org
if [ -n "$default_org" ]; then
# Validate organization exists
echo "正在验证组织..."
org_response=$(curl -s -w "\n%{http_code}" \
-H "Authorization: token $gitea_token" \
"${gitea_url}/api/v1/orgs/${default_org}")
org_http_code=$(echo "$org_response" | tail -n1)
if [ "$org_http_code" = "200" ]; then
echo "✓ 组织验证成功: $default_org"
else
echo "⚠️ 组织 '$default_org' 不存在或无权限访问"
read -p "仍然设置为默认组织? [Y/n] " set_anyway
if [[ "$set_anyway" =~ ^[Nn]$ ]]; then
default_org=""
fi
fi
fi
```
### 7. Save Configuration
```bash
echo ""
echo "正在保存配置..."
cat > "$config_file" << EOF
# Gitea Configuration
# Generated at $(date '+%Y-%m-%d %H:%M:%S')
GITEA_URL=$gitea_url
GITEA_TOKEN=$gitea_token
${default_org:+GITEA_DEFAULT_ORG=$default_org}
# Runner Default Settings
GITEA_RUNNER_CAPACITY=2
GITEA_RUNNER_TIMEOUT=3h
# Optional: Override auto-detected labels
# GITEA_RUNNER_LABELS=custom-label-1:host,custom-label-2:host
EOF
# Set restrictive permissions
chmod 600 "$config_file"
# Create .gitignore
cat > "$config_dir/.gitignore" << EOF
config.env
runners/*/.runner
runners/*/.env
EOF
echo "✓ 配置已保存"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "配置完成"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " 配置文件: $config_file"
echo " Runner 目录: $config_dir/runners"
echo ""
echo "下一步:"
echo " - 查看配置: /gitea-config"
echo " - 创建 Runner: 告诉 AI '创建一个 runner'"
echo " - 创建仓库: /create-gitea-repo <repo-name>"
echo ""
```
## Configuration File Format
生成的 `~/.config/gitea/config.env` 文件格式:
```bash
# Gitea Configuration
# Generated at 2026-01-12 22:00:00
GITEA_URL=https://git.digitevents.com
GITEA_TOKEN=git_xxxxxxxxxxxxxxxxxxxx
GITEA_DEFAULT_ORG=ai
# Runner Default Settings
GITEA_RUNNER_CAPACITY=2
GITEA_RUNNER_TIMEOUT=3h
# Optional: Override auto-detected labels
# GITEA_RUNNER_LABELS=custom-label-1:host,custom-label-2:host
```
## Output Example
```
开始 Gitea 配置向导...
请输入 Gitea 实例地址 (例如: https://git.digitevents.com): https://git.digitevents.com
✓ URL: https://git.digitevents.com
请输入 Personal Access Token: ****************
✓ Token 已输入
正在测试连接...
✓ 连接成功!
✓ 登录用户: your_username
正在检查 Token 权限...
✓ repo (仓库管理)
✓ admin:org (组织管理)
✓ write:runner (Runner 管理)
设置默认组织(可选):
- 创建仓库时,如果不指定 owner将使用默认组织
- 创建组织级 Runner 时使用
请输入默认组织名称 (回车跳过): ai
正在验证组织...
✓ 组织验证成功: ai
正在保存配置...
✓ 配置已保存
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
配置完成
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
配置文件: /Users/voson/.config/gitea/config.env
Runner 目录: /Users/voson/.config/gitea/runners
下一步:
- 查看配置: /gitea-config
- 创建 Runner: 告诉 AI '创建一个 runner'
- 创建仓库: /create-gitea-repo <repo-name>
```
## Security Notes
- 配置文件权限设置为 `600`(仅所有者可读写)
- Token 不会在日志中显示
- 创建 `.gitignore` 文件排除敏感信息
- 建议定期轮换 Token每 3-6 个月)
## Notes
- **必需权限**: `repo` - 创建和管理仓库
- **推荐权限**: `admin:org` - 创建组织级 Runner
- **推荐权限**: `write:runner` - 管理 Runner
- **可选权限**: `admin:repo_hook` - 配置 Webhooks
- Token 只显示一次,请妥善保管
- 重置配置不会影响已创建的 Runner但 Runner 会继续使用旧的注册信息