Commit61a6049unknown_key
fix(phase-b): migrate script uses form-urlencoded body for /import/github/repo
fix(phase-b): migrate script uses form-urlencoded body for /import/github/repo The /import/github/repo endpoint reads c.req.parseBody() expecting form fields, not JSON. Also returns 302 redirect, not 200. Fixed the script to: - Send Content-Type application/x-www-form-urlencoded with repo_url field - Not follow redirects, inspect Location header for success/error markers - Handle PowerShell's Invoke-WebRequest exception path on 302 (varies by version)
1 file changed+34−1461a604912f3a39db9df47766f5c60ee16ec7a75c
1 changed file+34−14
Modifiedscripts/migrate-to-gluecron.ps1+34−14View fileUnifiedSplit
@@ -57,24 +57,44 @@ try {
5757
5858# ─── 3. Trigger import from GitHub ──────────────────────────────────────────
5959Write-Host "[3/5] Importing $GH_OWNER/$GH_REPO from GitHub..."
60$importBody = @{
61 source = "github"
62 owner = $GH_OWNER
63 repo = $GH_REPO
64} | ConvertTo-Json
60$importForm = "repo_url=$([uri]::EscapeDataString("https://github.com/$GH_OWNER/$GH_REPO"))"
6561try {
66 $imported = Invoke-RestMethod -Method POST -Uri "$GLUECRON/import/github/repo" `
62 $r = Invoke-WebRequest -Method POST -Uri "$GLUECRON/import/github/repo" `
6763 -Headers @{ Authorization = "Bearer $PAT" } `
68 -ContentType "application/json" `
69 -Body $importBody -TimeoutSec 120
70 Write-Host " ✓ Repo mirrored to $GLUECRON/$GLUECRON_OWNER/$GH_REPO" -ForegroundColor Green
64 -ContentType "application/x-www-form-urlencoded" `
65 -Body $importForm `
66 -MaximumRedirection 0 `
67 -ErrorAction SilentlyContinue
68 $loc = $r.Headers.Location
69 if ($loc -match "success") {
70 Write-Host " ✓ Repo mirrored to $GLUECRON/$GLUECRON_OWNER/$GH_REPO" -ForegroundColor Green
71 } elseif ($loc -match "error=([^&]+)") {
72 $err = [uri]::UnescapeDataString($matches[1])
73 if ($err -match "already") {
74 Write-Host " ✓ Already imported (existing mirror)" -ForegroundColor Yellow
75 } else {
76 Write-Host " ✗ Import error: $err" -ForegroundColor Red
77 Write-Host " Manual import: $GLUECRON/import" -ForegroundColor Yellow
78 exit 1
79 }
80 } else {
81 Write-Host " ? Unexpected response (location: $loc)" -ForegroundColor Yellow
82 }
7183} catch {
72 $resp = $_.Exception.Response
73 if ($resp -and $resp.StatusCode -eq 409) {
74 Write-Host " ✓ Already imported (409 conflict is fine)" -ForegroundColor Yellow
84 # Invoke-WebRequest treats 302 as terminating in some PowerShell versions
85 if ($_.Exception.Response -and $_.Exception.Response.StatusCode.value__ -eq 302) {
86 $loc = $_.Exception.Response.Headers.Location.OriginalString
87 if ($loc -match "success") {
88 Write-Host " ✓ Repo mirrored to $GLUECRON/$GLUECRON_OWNER/$GH_REPO" -ForegroundColor Green
89 } elseif ($loc -match "already") {
90 Write-Host " ✓ Already imported (existing mirror)" -ForegroundColor Yellow
91 } else {
92 Write-Host " ✗ Import response: $loc" -ForegroundColor Red
93 Write-Host " Manual import: $GLUECRON/import" -ForegroundColor Yellow
94 }
7595 } else {
76 Write-Host " ✗ Import failed: $_" -ForegroundColor Red
77 Write-Host " You can also import manually at $GLUECRON/import"
96 Write-Host " ✗ Import call failed: $_" -ForegroundColor Red
97 Write-Host " Manual import: $GLUECRON/import" -ForegroundColor Yellow
7898 exit 1
7999 }
80100}
81101