Skip to content

Instantly share code, notes, and snippets.

@webbird
Last active August 29, 2015 13:55
Show Gist options
  • Save webbird/8728627 to your computer and use it in GitHub Desktop.
Save webbird/8728627 to your computer and use it in GitHub Desktop.
<?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']);
}
@webbird
Copy link
Author

webbird commented Jan 31, 2014

Changes:

  • enable use behind proxy
  • format output line using sprintf()
  • added another preg_match() to match string "issue [#]123" as I needed this for my project
  • remove doubles from result array
  • added a search for labels that contain "fixed" as i needed this for my project
  • use 'html_url' instead of 'url' for link

Example output line:

191/  open: Page properties flyout
     fixed: no
       URL: https://github.com/webbird/LEPTON_2_BlackCat/issues/191

Note: I preferred to have multiple lines per issue as oneliners may get quite long. Just tweak $outline to fit your needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment