Last active
July 15, 2019 08:22
-
-
Save dzentota/99455c076f8bb50fa8cc72cee9c0ec13 to your computer and use it in GitHub Desktop.
Get list of unmerged branches/commits
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
#!/usr/bin/env php | |
<?php | |
error_reporting(E_ALL); | |
ini_set('display_errors',1); | |
$token = '<your github token>'; | |
$username = '<your github username>'; | |
function query($condition) | |
{ | |
global $token; | |
$endpoint = 'https://api.github.com/search/issues?' . http_build_query(['q' => $condition]); | |
$c = curl_init(); | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($c,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
curl_setopt($c, CURLOPT_HTTPHEADER, array( | |
'Accept: application/vnd.github.cloak-preview', | |
'Content-Type: application/json', | |
'Authorization: token ' . $token | |
)); | |
curl_setopt($c, CURLOPT_URL, $endpoint); | |
$content = curl_exec($c); | |
curl_close($c); | |
return json_decode($content, true)['items']; | |
} | |
function pr($endpoint) | |
{ | |
global $token; | |
$c = curl_init(); | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($c,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
curl_setopt($c, CURLOPT_HTTPHEADER, array( | |
'Accept: application/vnd.github.cloak-preview', | |
'Content-Type: application/json', | |
'Authorization: token ' . $token | |
)); | |
curl_setopt($c, CURLOPT_URL, $endpoint); | |
$content = curl_exec($c); | |
curl_close($c); | |
return json_decode($content, true); | |
} | |
function getUnmerged($type = 'sha') | |
{ | |
global $username; | |
if (!in_array($type, ['sha', 'ref'])) { | |
die('Invalid type. Expected "sha" or "ref"'); | |
} | |
$myPRs = query("repo:sugarcrm/Mango type:pr author:{$username} state:open"); | |
$result = []; | |
foreach ($myPRs as $pr) { | |
echo "."; | |
$prData = pr($pr['pull_request']['url']); | |
$result[] = $prData['head'][$type]; | |
} | |
echo PHP_EOL; | |
echo implode(' ', $result); | |
} | |
if (!empty($argv[1])) { | |
getUnmerged($argv[1]); | |
} else { | |
getUnmerged(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment