Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save RobbWatershed/374e31c92801abf709400588ec1c7b82 to your computer and use it in GitHub Desktop.

Select an option

Save RobbWatershed/374e31c92801abf709400588ec1c7b82 to your computer and use it in GitHub Desktop.
migrate MD issue to codeberg
Write-Output "Waiting..."
Start-Sleep -Seconds 305 # 5 mins and a few more secs
Write-Output "Let's move!"
Get-ChildItem '*.md' -File | ForEach-Object {
$file = $_
$title = ""
$descriptionStart = $false
$description = ""
#$labels = @()
$labels = [System.Collections.Generic.List[int]]@()
$reachedLabel = $false
Get-Content $file | ForEach-Object {
if ($descriptionStart) {
$description += $_ + [Environment]::NewLine
} else {
# Name
if ($_ -match '^# issue ([\d]+): (.+)') {
$title = $Matches.2
}
# Labels
if ($_ -match '^Labels: (.+)' -or $reachedLabel) {
$label = ""
if ($reachedLabel) {
$label = $_
} else {
$label = $Matches.1
$reachedLabel = $true
}
if ($label -eq 'UX') { $labels += 1332693 }
else { if ($label -eq 'technical') { $labels += 1332690 }
else { if ($label -eq 'source') { $labels += 1332207 }
else { if ($label -eq 'Q&A') { $labels += 1332198 }
else { if ($label -eq 'more info needed') { $labels += 1332687 }
else { if ($label -eq 'enhancement') { $labels += 1332186 }
else { if ($label -eq 'bug') { $labels += 1332180 }
}
}
}
}
}
}
}
if ($_.length -eq 0) {
$reachedLabel = $false
}
# Description
if ($_ -eq '---') {
$descriptionStart = $true
}
}
}
Write-Output $title
Write-Output $labels
Write-Output $description
# POST to API
$token="token"
if ($labels.count -gt 0) {
$labelStr = ,$labels[0] | ConvertTo-Json -Compress
Write-Output $labelStr
$postParams = @{body=$description;labels=$labelStr;title=$title}
} else {
$postParams = @{body=$description;title=$title}
}
Write-Output $postParams
$headers = @{Authorization="token "+$token}
Invoke-WebRequest -Uri https://codeberg.org/api/v1/repos/user/repo/issues -Method POST -Headers $headers -Body $postParams
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment