Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mavaddat/6d92f4fc3b52eddbdf44af96c6eb034b to your computer and use it in GitHub Desktop.
Save mavaddat/6d92f4fc3b52eddbdf44af96c6eb034b to your computer and use it in GitHub Desktop.
Powershell - Github Api - List Pull Requests - Basic Authentication
# See https://developer.github.com/v3/pulls/#list-pull-requests
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
# If using token...
$ghcred = Get-Credential -Message "Please provide your username and GitHub token" -Title "Github Personal Access Token"
$headers = @{"Authorization"="token $($ghcred.Password | ConvertFrom-SecureString -AsPlainText)"}
# Else if using basic
$ghcredBase64=[System.Convert]::ToBase64String( $([System.Text.Encoding]::ASCII.GetBytes($ghcred.UserName+':')) + $( [System.Convert]::FromHexString($($ghcred.Password | ConvertFrom-SecureString)) ))
$headers = @{"Authorization"="basic $ghcredBase64"}
$endpoint = "https://api.github.com/repos/[Owner]/[Repo]/pulls?state=[state]"
$val = Invoke-WebRequest -Uri $endpoint -Headers $headers
$json = $val | ConvertFrom-JSON
foreach($obj in $json)
{
Write-Host "Pull request: #" + $obj.number
Write-Host "Title: " + $obj.title
Write-Host "Url: " + $obj.url
$releaseNotes = $releaseNotes + "Body: "
$obj.body.Split("`n") | ForEach {
# ignore comments from issue templates
if($_.Trim().StartsWith("<!---") -eq $FALSE)
{
$releaseNotes = $releaseNotes + $_ + "`n"
}
}
$releaseNotes = $releaseNotes + "`n"
Write-Host "User: " + $obj.user.login
Write-Host ""
}
@mavaddat
Copy link
Author

I need to modify this to be a proper cmdlet... 🚧👷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment