Skip to content

Instantly share code, notes, and snippets.

@sagotsky
Last active December 15, 2015 06:19
Show Gist options
  • Save sagotsky/5215739 to your computer and use it in GitHub Desktop.
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).
<?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';
}
@sagotsky
Copy link
Author

From github support:

You can use the HTML Media Type[1] to get the rendered markdown in the body_html attribute.
curl -H "Accept: appliation/vnd.github.html" https://api.github.com/repos/pengwynn/octonaut/issues/3
http://developer.github.com/v3/media/

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