Last active
August 29, 2015 13:55
-
-
Save webbird/8728627 to your computer and use it in GitHub Desktop.
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
<?php | |
// Configuration | |
$organization = '<your organization>'; | |
$project = '<your project>'; | |
$token = '<your token>'; | |
$proxy = '<proxy>:<port>'; | |
$outline = '%5s/%6s: %s'."\n".' fixed: %s'."\n".' URL: %s'."\n\n"; | |
// Find latest version | |
exec('git tag', $tags, $return); | |
usort($tags, 'version_compare'); | |
$latest = array_pop($tags); | |
// Get commits since latest version | |
exec('git log ' . $latest . '...HEAD --oneline', $commits, $return); | |
// Filter commits that reference an issue | |
foreach ($commits as $commit) { | |
if (preg_match('/[close|closes|fix|fixes] #([0-9]+)/i', $commit, $matches) && isset($matches[1])) { | |
$issues[] = $matches[1]; | |
} | |
elseif (preg_match('/issue #?([0-9]+)/i', $commit, $matches) && isset($matches[1])) { | |
$issues[] = $matches[1]; | |
} | |
} | |
// sort by ID | |
sort($issues); | |
// remove doubles | |
$issues = array_unique($issues); | |
// Query GitHub | |
$url = sprintf('https://api.github.com/repos/%s/%s/issues/', $organization, $project); | |
$headers = array( | |
'Authorization: token ' . $token, | |
'User-Agent: php-curl' | |
); | |
foreach ($issues as $id) { | |
$ch = curl_init($url . $id); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
if($proxy) | |
curl_setopt($ch, CURLOPT_PROXY, $proxy); | |
// quick & dirty hack for "invalid certificate" error | |
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$issue = json_decode(curl_exec($ch), true); | |
// search for labels containing string 'fixed'; you may remove this if you don't need it | |
// just remember to remove it from the output line, too | |
$fixed = false; | |
if(isset($issue['labels'])) | |
foreach($issue['labels'] as $l) | |
if(substr_count($l['name'],'fixed')) | |
$fixed = true; | |
echo sprintf($outline,$id,$issue['state'],$issue['title'],($fixed?'yes':'no'),$issue['html_url']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changes:
Example output line:
Note: I preferred to have multiple lines per issue as oneliners may get quite long. Just tweak
$outline
to fit your needs.