Forked from majorsilence/powershell_github_basic_auth.ps1
Last active
January 19, 2022 21:23
-
-
Save mavaddat/6d92f4fc3b52eddbdf44af96c6eb034b to your computer and use it in GitHub Desktop.
Powershell - Github Api - List Pull Requests - Basic Authentication
This file contains hidden or 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
# 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 "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need to modify this to be a proper cmdlet... 🚧👷