Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created January 2, 2014 19:12
Show Gist options
  • Save eminetto/8224766 to your computer and use it in GitHub Desktop.
Save eminetto/8224766 to your computer and use it in GitHub Desktop.
<?php
require_once 'vendor/autoload.php';
if ($argc < 2) {
echo "Usage: php index.php ProjectName\n";
exit;
}
$projectName = $argv[1];
$client = new \Github\Client(
new \Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache'))
);
$client->authenticate('username', 'password', \Github\Client::AUTH_HTTP_PASSWORD);
//get sprints
$sprints = array();
$milestones = $client->api('issue')->milestones()->all('coderockr', $projectName, array('direction' => 'asc'));
foreach ($milestones as $m) {
$sprints[$m['id']] = array(
'name' => $m['title'],
'open_issues' => $m['open_issues'],
'closed_issues' => $m['closed_issues'],
'state' => $m['state'],
'due_on' => $m['due_on'],
'open_points' => 0,
'closed_points' => 0,
);
}
//get issues
$issues = array_merge(
$client->api('issue')->all('coderockr', $projectName, array('state' => 'open')),
$client->api('issue')->all('coderockr', $projectName, array('state' => 'closed'))
);
//update sprint points
foreach ($issues as $i) {
$milestone = $i['milestone'];
switch ($i['state']) {
case 'open':
$open_points = $sprints[$milestone['id']]['open_points'];
foreach ($i['labels'] as $l) {
$open_points += (float) $l['name'];
}
$sprints[$milestone['id']]['open_points'] = $open_points;
break;
case 'closed':
$closed_points = $sprints[$milestone['id']]['closed_points'];
foreach ($i['labels'] as $l) {
$closed_points += (float) $l['name'];
}
$sprints[$milestone['id']]['closed_points'] = $closed_points;
break;
}
}
//show sprint's details
$total_open_points = 0;
$total_closed_points = 0;
foreach ($sprints as $s) {
$sprint_points = $s['open_points'] + $s['closed_points'];
$sprint_issues = $s['open_issues'] + $s['closed_issues'];
echo "{$s['name']} due on {$s['due_on']} has {$s['closed_issues']} closed of {$sprint_issues} issues and {$s['closed_points']} closed of {$sprint_points} points\n";
$total_open_points += $s['open_points'];
$total_closed_points += $s['closed_points'];
}
//show project's details
$project_points = $total_open_points + $total_closed_points;
echo "Project have {$total_closed_points} closed of {$project_points} points \n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment