tidy and better comment
This commit is contained in:
parent
9ab50f6bc4
commit
e869bc2d8e
@ -9,6 +9,11 @@
|
|||||||
// we will then have $client and $repo available
|
// we will then have $client and $repo available
|
||||||
require 'setup.php';
|
require 'setup.php';
|
||||||
|
|
||||||
|
// set the repo username and month to get the report for
|
||||||
|
echo "Enter username for report: ";
|
||||||
|
$name = trim(fgets(STDIN)); // read from stdin
|
||||||
|
$date = date('Y-m', strtotime('now -1 month')); //last month
|
||||||
|
echo "Generateing report for {$repo->user}/{$repo->repo} of time spent in month $date by $name...\n";
|
||||||
// Build a crazy id to number lookup table
|
// Build a crazy id to number lookup table
|
||||||
// https://github.com/go-gitea/gitea/issues/8513
|
// https://github.com/go-gitea/gitea/issues/8513
|
||||||
foreach ($repo->getIssues() as $issue) {
|
foreach ($repo->getIssues() as $issue) {
|
||||||
@ -25,35 +30,45 @@ foreach ($repo->getPulls(['state' => 'closed']) as $pull) {
|
|||||||
$issue = $repo->getIssue($pull->number);
|
$issue = $repo->getIssue($pull->number);
|
||||||
$issueNumbers[$issue->id] = $issue->number;
|
$issueNumbers[$issue->id] = $issue->number;
|
||||||
}
|
}
|
||||||
$name = 'jhodges';
|
|
||||||
$date = '2019-10';
|
|
||||||
|
|
||||||
$sums = [];
|
// process and sum up all the times by issue number
|
||||||
|
// (not ID as retrned by API)
|
||||||
|
$totals = [];
|
||||||
foreach ($repo->getTimesByUsername($name) as $time) {
|
foreach ($repo->getTimesByUsername($name) as $time) {
|
||||||
|
// check the month
|
||||||
if ($date == date('Y-m', strtotime($time->created))) {
|
if ($date == date('Y-m', strtotime($time->created))) {
|
||||||
|
// get the issue number
|
||||||
$number = $issueNumbers[$time->issue_id];
|
$number = $issueNumbers[$time->issue_id];
|
||||||
if (!isset($sums[$number])) {
|
// if we've not already got a total for this issue
|
||||||
|
// then create the entry, looking up issue title
|
||||||
|
if (!isset($totals[$number])) {
|
||||||
$issue = $repo->getIssue($number);
|
$issue = $repo->getIssue($number);
|
||||||
$sums[$number] = [
|
$totals[$number] = [
|
||||||
'id' => $number,
|
'id' => $number,
|
||||||
'name' => $issue->title,
|
'name' => $issue->title,
|
||||||
'time' => 0,
|
'time' => 0,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$sums[$number]['time'] += $time->time;
|
// add the time to the total
|
||||||
|
$totals[$number]['time'] += $time->time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper to format seconds into H:M:S format
|
||||||
function format_time($t)
|
function format_time($t)
|
||||||
{
|
{
|
||||||
return sprintf('%02d:%02d:%02d', floor($t / 3600), ($t / 60) % 60, $t % 60);
|
return sprintf('%02d:%02d:%02d', floor($t / 3600), ($t / 60) % 60, $t % 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save the report
|
||||||
$f = fopen('report.csv', 'w');
|
$f = fopen('report.csv', 'w');
|
||||||
|
// ouput headers
|
||||||
fputcsv($f, ['ID', 'Description', 'Hours', 'H:M:S']);
|
fputcsv($f, ['ID', 'Description', 'Hours', 'H:M:S']);
|
||||||
foreach ($sums as $id => $data) {
|
// output data
|
||||||
$data['hours'] = $data['time']/60/60;
|
foreach ($totals as $id => $data) {
|
||||||
$data['hms'] = format_time($data['time']);
|
$data['hours'] = $data['time']/60/60; //decimal hours
|
||||||
|
$data['hms'] = format_time($data['time']); //H:M:S
|
||||||
|
unset($data['time']); //dont want seconds in the report
|
||||||
fputcsv($f, $data);
|
fputcsv($f, $data);
|
||||||
}
|
}
|
||||||
fclose($f);
|
fclose($f);
|
||||||
|
Loading…
Reference in New Issue
Block a user