Last active
December 15, 2015 06:19
-
-
Save sagotsky/5215739 to your computer and use it in GitHub Desktop.
Fetches our release notes from git. Only gets issues from the most recent closed milestone that use a specific label ("type: bug" for proof of concept).
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 | |
function os_releasenotes() { | |
$milestones = _os_releasenotes_milestones('closed'); | |
$latest = $milestones[0]; | |
$api_url = 'https://api.github.com/repos/openscholar/openscholar/issues'; | |
//get labeled issues | |
$params = array('state' => 'closed', 'labels' => 'type: bug', 'milestone' => $latest['number']); | |
$query_params = array(); | |
foreach ($params as $k => $v) { | |
$query_params[] = $k . '=' . str_replace(' ', '%20', $v); //api func for this? | |
} | |
$url = $api_url . '?' . implode('&', $query_params); | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
$result = curl_exec($curl); | |
//what about getting latest copmleted milestone | |
if (!$result) { | |
$info = curl_getinfo($curl); | |
dpm($info); | |
curl_close($curl); | |
return 'curl error'; | |
} | |
curl_close($curl); | |
$json = drupal_json_decode($result); | |
//dpm($json); | |
$txt = '<h1>' . $latest['description']. '</h1>'; | |
$total = $latest['closed_issues']+$latest['open_issues']; | |
$txt .= '<p><em>' . $latest['title'] . '</em> - ' . $latest['closed_issues'] . '/' . $total . ' issues closed</p>'; | |
foreach ($json as $issue) { | |
$txt .= '<p>'; | |
$txt .= '<strong>' . $issue['title'] . '</strong><br />'; | |
$txt .= l($issue['url'], $issue['url']) . '<br />'; | |
foreach ($issue['labels'] as $label) { | |
$txt .= '[<span style="color: #'.$label['color'].'">' . $label['name'] . '</span>] '; | |
} | |
$txt .= '<br />' . $issue['body']; | |
$txt .= '</p>'; | |
} | |
return $txt; | |
} | |
function _os_releasenotes_milestones($state = NULL) { | |
$url = 'https://api.github.com/repos/openscholar/openscholar/milestones'; | |
if ($state && in_array($state, array('open', 'closed'))) { | |
$url .= '?state=' . $state; | |
} | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
$result = curl_exec($curl); | |
curl_close($curl); | |
if (!$result) { | |
return 'milestone error'; | |
} | |
return ($result) ? drupal_json_decode($result) : 'milestone error'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From github support: