Files
opencode/command/gitea-switch-org.md

1.9 KiB
Raw Blame History

description
description
Switch default Gitea organization

Switch the default Gitea organization in configuration.

工作目录

macOS / Linux:

~/.config/gitea/

Windows:

%USERPROFILE%\.config\gitea\

User input format: $ARGUMENTS = organization name

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:

source ~/.config/gitea/config.env

Windows PowerShell:

Get-Content "$env:USERPROFILE\.config\gitea\config.env" | ForEach-Object {
    if ($_ -match '^([^=]+)=(.*)$') {
        [Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process')
    }
}
  1. Parse user input:

    • Organization name from $ARGUMENTS
    • If empty: show usage and examples
  2. 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:
      curl -s -H "Authorization: token $GITEA_TOKEN" \
        "${GITEA_URL}/api/v1/user/orgs" | jq -r '.[].username'
      
  3. 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
  4. Display result in Chinese:

✓ 默认组织已切换到: [org_name]

现在可以:
  - 创建仓库: /create-gitea-repo my-project
    (将创建到 [org_name]/my-project
  - 查看配置: /gitea-config

Notes:

  • Switching organization doesn't affect existing repositories or runners
  • Only affects default owner for future repository creation
  • Can switch anytime