Created
February 13, 2019 17:50
-
-
Save elranu/1ca5fb40ecd468eb235ec74f0f254553 to your computer and use it in GitHub Desktop.
github PR upsert
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
$Token = 'username:token89898989'; | |
$Base64Token = [System.Convert]::ToBase64String([char[]]$Token); | |
$Headers = @{ AUTHORIZATION= "Basic $Base64Token" }; | |
$Body = '{ | |
"title": "Title", | |
"body": "Please merge this PR", | |
"head": "user:headBranch", | |
"base": "baseBranch" | |
}'; | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; | |
$rest = Invoke-RestMethod -Headers $Headers -Uri https://api.github.com/repos/{user}/{repo}/pulls?head=user:headbranch -Method Get | |
if($rest.state){ | |
#update | |
$uri = "https://api.github.com/repos/{user}/{repo}/pulls/" + $rest.number; | |
Invoke-RestMethod -Headers $Headers -Uri $uri -Method Patch -Body '{"title": "new Title"}'; | |
} | |
else{ | |
#create | |
Invoke-RestMethod -Headers $Headers -Uri https://api.github.com/repos/{user}/{repo}/pulls -Method Post -Body $Body | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment