# 更新 GitHub Token 脚本 # 用途:更新 Git 远程 URL 中的 token param( [Parameter(Mandatory=$true)] [string]$NewToken ) Write-Host "=== 更新 GitHub Token ===" -ForegroundColor Cyan Write-Host "" # 验证 token 格式 if ($NewToken -notmatch '^ghp_[A-Za-z0-9]{36}$') { Write-Host "警告: Token 格式可能不正确(应以 ghp_ 开头)" -ForegroundColor Yellow $continue = Read-Host "是否继续? (y/n)" if ($continue -ne "y" -and $continue -ne "Y") { exit 1 } } # 更新远程 URL Write-Host "更新 Git 远程 URL..." -ForegroundColor Yellow git remote set-url origin "https://bujie9527:${NewToken}@github.com/bujie9527/wecom-ai-assistant.git" Write-Host "✓ 远程 URL 已更新" -ForegroundColor Green # 验证 Write-Host "" Write-Host "验证远程配置:" -ForegroundColor Cyan $remoteUrl = git remote get-url origin # 隐藏 token 显示 $safeUrl = $remoteUrl -replace ':(ghp_[^@]+)@', ':****@' Write-Host " $safeUrl" -ForegroundColor Gray # 更新配置文件 Write-Host "" Write-Host "更新配置文件..." -ForegroundColor Yellow $configFile = ".github-config" if (Test-Path $configFile) { $content = Get-Content $configFile $newContent = $content | ForEach-Object { if ($_ -match '^GITHUB_TOKEN=') { "GITHUB_TOKEN=${NewToken}" } else { $_ } } $newContent | Set-Content $configFile Write-Host "✓ 配置文件已更新" -ForegroundColor Green } else { Write-Host "⚠ 配置文件不存在,跳过更新" -ForegroundColor Yellow } Write-Host "" Write-Host "=== 完成 ===" -ForegroundColor Green Write-Host "" Write-Host "现在可以尝试推送:" -ForegroundColor Cyan Write-Host " git push -u origin main" -ForegroundColor Gray Write-Host "" Write-Host "如果仍然遇到权限问题,请确认 token 包含以下权限:" -ForegroundColor Yellow Write-Host " - repo (完整仓库访问)" -ForegroundColor Gray Write-Host " - workflow (工作流权限) ← 必需" -ForegroundColor Gray Write-Host " - write:packages (推送镜像)" -ForegroundColor Gray Write-Host " - read:packages (拉取镜像)" -ForegroundColor Gray