Add documentation and scripts
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
95
scripts/fix-git-network.ps1
Normal file
95
scripts/fix-git-network.ps1
Normal file
@@ -0,0 +1,95 @@
|
||||
# Git 网络连接问题修复脚本
|
||||
# 用途:配置 Git 代理或切换到 SSH
|
||||
|
||||
param(
|
||||
[string]$ProxyHost = "127.0.0.1",
|
||||
[int]$ProxyPort = 7890,
|
||||
[switch]$UseSSH,
|
||||
[switch]$RemoveProxy
|
||||
)
|
||||
|
||||
Write-Host "=== Git 网络连接问题修复 ===" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
if ($RemoveProxy) {
|
||||
Write-Host "移除 Git 代理配置..." -ForegroundColor Yellow
|
||||
git config --global --unset http.proxy 2>$null
|
||||
git config --global --unset https.proxy 2>$null
|
||||
git config --global --unset http.https://github.com.proxy 2>$null
|
||||
git config --global --unset https.https://github.com.proxy 2>$null
|
||||
Write-Host "✓ 代理配置已移除" -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($UseSSH) {
|
||||
Write-Host "切换到 SSH 连接..." -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
# 检查 SSH 密钥是否存在
|
||||
$sshKeyPath = "$env:USERPROFILE\.ssh\id_ed25519.pub"
|
||||
if (-not (Test-Path $sshKeyPath)) {
|
||||
Write-Host "未找到 SSH 密钥,正在生成..." -ForegroundColor Yellow
|
||||
ssh-keygen -t ed25519 -C "bujie9527@github.com" -f "$env:USERPROFILE\.ssh\id_ed25519" -N '""'
|
||||
Write-Host "✓ SSH 密钥已生成" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# 显示公钥
|
||||
Write-Host ""
|
||||
Write-Host "SSH 公钥内容(需要添加到 GitHub):" -ForegroundColor Cyan
|
||||
Write-Host "---"
|
||||
Get-Content $sshKeyPath
|
||||
Write-Host "---"
|
||||
Write-Host ""
|
||||
Write-Host "请执行以下步骤:" -ForegroundColor Yellow
|
||||
Write-Host "1. 复制上面的公钥内容" -ForegroundColor Gray
|
||||
Write-Host "2. 访问: https://github.com/settings/keys" -ForegroundColor Gray
|
||||
Write-Host "3. 点击 'New SSH key'" -ForegroundColor Gray
|
||||
Write-Host "4. 粘贴公钥并保存" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
$continue = Read-Host "已添加 SSH 密钥到 GitHub? (y/n)"
|
||||
if ($continue -eq "y" -or $continue -eq "Y") {
|
||||
# 测试 SSH 连接
|
||||
Write-Host "测试 SSH 连接..." -ForegroundColor Yellow
|
||||
$testResult = ssh -T git@github.com 2>&1
|
||||
if ($testResult -match "successfully authenticated") {
|
||||
Write-Host "✓ SSH 连接成功" -ForegroundColor Green
|
||||
|
||||
# 更改远程 URL
|
||||
Write-Host "更改远程仓库 URL 为 SSH..." -ForegroundColor Yellow
|
||||
git remote set-url origin git@github.com:bujie9527/wecom-ai-assistant.git
|
||||
Write-Host "✓ 远程 URL 已更改为 SSH" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "现在可以尝试推送:" -ForegroundColor Cyan
|
||||
Write-Host " git push -u origin main" -ForegroundColor Gray
|
||||
} else {
|
||||
Write-Host "✗ SSH 连接失败,请检查 SSH 密钥是否正确添加到 GitHub" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-Host "配置 Git HTTP/HTTPS 代理..." -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
Write-Host "代理地址: http://${ProxyHost}:${ProxyPort}" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# 仅针对 GitHub 设置代理
|
||||
git config --global http.https://github.com.proxy "http://${ProxyHost}:${ProxyPort}"
|
||||
git config --global https.https://github.com.proxy "http://${ProxyHost}:${ProxyPort}"
|
||||
|
||||
Write-Host "✓ 代理已配置" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "验证配置:" -ForegroundColor Yellow
|
||||
git config --global --get http.https://github.com.proxy
|
||||
git config --global --get https.https://github.com.proxy
|
||||
Write-Host ""
|
||||
Write-Host "现在可以尝试推送:" -ForegroundColor Cyan
|
||||
Write-Host " git push -u origin main" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "如果代理端口不同,请使用:" -ForegroundColor Yellow
|
||||
Write-Host " .\scripts\fix-git-network.ps1 -ProxyPort 你的端口号" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "其他选项:" -ForegroundColor Cyan
|
||||
Write-Host " - 切换到 SSH: .\scripts\fix-git-network.ps1 -UseSSH" -ForegroundColor Gray
|
||||
Write-Host " - 移除代理: .\scripts\fix-git-network.ps1 -RemoveProxy" -ForegroundColor Gray
|
||||
64
scripts/update-github-token.ps1
Normal file
64
scripts/update-github-token.ps1
Normal file
@@ -0,0 +1,64 @@
|
||||
# 更新 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
|
||||
Reference in New Issue
Block a user