# 使用 API 创建 Git 仓库 # 支持 Gitea 和 GitLab $gitUrl = "https://git.quanyu360.cn" $username = "admin" $password = "ye972030" $repoName = "wecom-ai-assistant" $isPrivate = $true Write-Host "=== 使用 API 创建 Git 仓库 ===" -ForegroundColor Cyan Write-Host "" # 尝试 Gitea API Write-Host "尝试 Gitea API..." -ForegroundColor Yellow $giteaApiUrl = "${gitUrl}/api/v1/user/repos" $body = @{ name = $repoName private = $isPrivate } | ConvertTo-Json $base64Auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${username}:${password}")) $headers = @{ "Authorization" = "Basic $base64Auth" "Content-Type" = "application/json" } try { $response = Invoke-RestMethod -Uri $giteaApiUrl -Method POST -Headers $headers -Body $body -ErrorAction Stop Write-Host "✓ 仓库创建成功!" -ForegroundColor Green Write-Host " 仓库 URL: $($response.clone_url)" -ForegroundColor Gray Write-Host "" # 配置远程仓库并推送 Write-Host "配置远程仓库..." -ForegroundColor Yellow git remote remove private 2>$null git remote add private "https://${username}:${password}@${gitUrl}/admin/${repoName}.git" Write-Host "推送代码..." -ForegroundColor Yellow git push -u private main if ($LASTEXITCODE -eq 0) { Write-Host "✓ 代码推送成功!" -ForegroundColor Green } } catch { Write-Host "✗ Gitea API 创建失败: $_" -ForegroundColor Red Write-Host "" Write-Host "请手动创建仓库:" -ForegroundColor Yellow Write-Host "1. 访问: $gitUrl" -ForegroundColor Gray Write-Host "2. 登录并创建新仓库: $repoName" -ForegroundColor Gray Write-Host "3. 然后运行: git push -u private main" -ForegroundColor Gray }