Skip to content

Instantly share code, notes, and snippets.

@elranu
Created February 13, 2019 17:50
Show Gist options
  • Save elranu/1ca5fb40ecd468eb235ec74f0f254553 to your computer and use it in GitHub Desktop.
Save elranu/1ca5fb40ecd468eb235ec74f0f254553 to your computer and use it in GitHub Desktop.
github PR upsert
$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