docs: 重构命令和技能文档体系,规范化文档格式和内容组织

This commit is contained in:
2026-01-13 10:25:18 +08:00
parent 5a05d5ab53
commit f31f198407
19 changed files with 1055 additions and 2342 deletions

View File

@@ -2,154 +2,81 @@
description: Switch default Gitea organization
---
# gitea-switch-org
Switch the default Gitea organization in configuration.
切换默认 Gitea 组织。
## Features
- 更新配置文件中的默认组织
- 验证组织是否存在
- 立即生效,无需重启
## User Input Format
## 工作目录
**macOS / Linux:**
```
<organization_name>
~/.config/gitea/
```
**Examples**:
- `ai` - Switch to 'ai' organization
- `my-team` - Switch to 'my-team' organization
**Windows:**
```
%USERPROFILE%\.config\gitea\
```
## Steps
**User input format:** `$ARGUMENTS` = organization name
### 1. Check Configuration
**Example usage:**
```
/gitea-switch-org ai
/gitea-switch-org my-team
```
Please perform the following:
1. **Check configuration exists:**
- Config file:
- macOS/Linux: `~/.config/gitea/config.env`
- Windows: `%USERPROFILE%\.config\gitea\config.env`
- If not exists: prompt user to run `/gitea-reset`
2. **Load configuration:**
**macOS / Linux:**
```bash
config_file="$HOME/.config/gitea/config.env"
if [ ! -f "$config_file" ]; then
echo "❌ Gitea 未配置"
echo "请先运行 /gitea-reset 进行配置"
exit 1
fi
source "$config_file"
source ~/.config/gitea/config.env
```
### 2. Parse User Input
```bash
new_org="$1"
if [ -z "$new_org" ]; then
echo "用法: /gitea-switch-org <organization_name>"
echo ""
echo "示例:"
echo " /gitea-switch-org ai"
echo " /gitea-switch-org my-team"
exit 1
fi
**Windows PowerShell:**
```powershell
Get-Content "$env:USERPROFILE\.config\gitea\config.env" | ForEach-Object {
if ($_ -match '^([^=]+)=(.*)$') {
[Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process')
}
}
```
### 3. Validate Organization Exists
3. **Parse user input:**
- Organization name from `$ARGUMENTS`
- If empty: show usage and examples
```bash
echo "正在验证组织 '$new_org'..."
4. **Validate organization exists:**
- API: `GET ${GITEA_URL}/api/v1/orgs/${org_name}`
- Header: `Authorization: token ${GITEA_TOKEN}`
- If 404: Show error and list available organizations:
```bash
curl -s -H "Authorization: token $GITEA_TOKEN" \
"${GITEA_URL}/api/v1/user/orgs" | jq -r '.[].username'
```
response=$(curl -s -w "\n%{http_code}" \
-H "Authorization: token $GITEA_TOKEN" \
"${GITEA_URL}/api/v1/orgs/${new_org}")
5. **Update configuration file:**
- If `GITEA_DEFAULT_ORG` exists: update the line
- If not exists: add after `GITEA_TOKEN`
- Handle macOS (sed -i '') and Linux (sed -i) differences
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" != "200" ]; then
echo "❌ 组织 '$new_org' 不存在或无权限访问"
# Suggest available organizations
echo ""
echo "你可以访问的组织:"
curl -s -H "Authorization: token $GITEA_TOKEN" \
"${GITEA_URL}/api/v1/user/orgs" | jq -r '.[].username' | sed 's/^/ - /'
exit 1
fi
org_name=$(echo "$body" | jq -r '.full_name // .username')
echo "✓ 组织验证成功: $org_name"
6. **Display result in Chinese:**
```
### 4. Update Configuration File
```bash
echo "正在更新配置..."
# Check if GITEA_DEFAULT_ORG already exists in config
if grep -q "^GITEA_DEFAULT_ORG=" "$config_file"; then
# Update existing line (macOS compatible)
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/^GITEA_DEFAULT_ORG=.*/GITEA_DEFAULT_ORG=$new_org/" "$config_file"
else
sed -i "s/^GITEA_DEFAULT_ORG=.*/GITEA_DEFAULT_ORG=$new_org/" "$config_file"
fi
else
# Add new line after GITEA_TOKEN
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "/^GITEA_TOKEN=/a\\
GITEA_DEFAULT_ORG=$new_org
" "$config_file"
else
sed -i "/^GITEA_TOKEN=/a GITEA_DEFAULT_ORG=$new_org" "$config_file"
fi
fi
echo "✓ 默认组织已切换到: $new_org"
```
### 5. Display Summary
```bash
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "切换完成"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " 新的默认组织: $new_org"
echo ""
echo "现在可以:"
echo " - 创建仓库: /create-gitea-repo my-project"
echo " (将创建到 $new_org/my-project"
echo " - 查看配置: /gitea-config"
echo ""
```
## Output Example
```
正在验证组织 'ai'...
✓ 组织验证成功: AI Team
正在更新配置...
✓ 默认组织已切换到: ai
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
切换完成
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
新的默认组织: ai
✓ 默认组织已切换到: [org_name]
现在可以:
- 创建仓库: /create-gitea-repo my-project
(将创建到 ai/my-project
(将创建到 [org_name]/my-project
- 查看配置: /gitea-config
```
## Notes
- 切换组织不会影响已创建的仓库和 Runner
- 仅影响后续创建仓库时的默认 owner
- 可以随时切换到其他组织
- 使用 `jq` 解析 JSON 响应
- macOS 和 Linux 的 `sed` 命令略有不同,需兼容处理
**Notes:**
- Switching organization doesn't affect existing repositories or runners
- Only affects default owner for future repository creation
- Can switch anytime