Created
October 26, 2019 21:47
-
-
Save felixfbecker/3a629e412d016812023758c4c625d841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Module PSGitHub | |
#Requires -Module PowerGit | |
[CmdletBinding()] | |
param() | |
$items = Get-Content not-needed-packages.txt | Select-String -Pattern 'Typings already defined for ([^ ]+)' -Context 0,5 | |
$i = 0 | |
$items | ForEach-Object { | |
$i++ | |
$pkg = $_.Matches.Groups[1] | |
Write-Verbose "$i/$($items.Length): $pkg" | |
try { | |
$yarnCmd = $_.Context.PostContext[2].Trim() | |
$prDescr = $_.Context.PostContext[4].Replace('And comment PR: ', '').Trim() | |
$title = "$($pkg): Provides its own types" | |
if (-not (Test-Path "types/$pkg")) { | |
Write-Verbose "$pkg does not exist anymore" | |
return | |
} | |
Write-Verbose "Package: $pkg" | |
Write-Verbose $yarnCmd | |
Write-Verbose $prDescr | |
$pr = Find-GitHubPullRequest "repo:DefinitelyTyped/DefinitelyTyped `"$title`" in:title is:pr" | |
if ($pr) { | |
Write-Verbose "Pull Request already exists: $($pr.WebUrl)" | |
return | |
} | |
Set-GitHead master -ErrorAction Stop | Out-Null | |
New-GitBranch -Name "not-needed-$pkg" -ErrorAction Stop | Out-Null | |
Invoke-Expression $yarnCmd | |
if ($LASTEXITCODE -ne 0) { | |
throw "yarn failed" | |
} | |
Add-GitItem -All | Out-Null | |
Save-GitCommit -Message $title | Out-Null | |
Send-GitBranch -SetUpstream -ErrorAction Stop | New-GitHubPullRequest ` | |
-Owner DefinitelyTyped ` | |
-ForkOwner felixfbecker ` | |
-Body $prDescr | |
Write-Progress -Activity "Processing packages" -Status "Package $i/$($items.Count) $pkg" -PercentComplete (($i / $items.Count) * 100) | |
} catch { | |
Write-Error -ErrorRecord $_ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment