Files
wecom-ai-assistant/scripts/create-repo-api.ps1
bujie9527 27a794eef1 Add repository creation guide
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-05 20:14:41 +08:00

52 lines
1.7 KiB
PowerShell

# 使用 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
}