update to use new api, much cleaner code now :)

This commit is contained in:
Bob E Moe 2020-01-18 09:15:10 +00:00
parent e869bc2d8e
commit 100b941b08

View File

@ -12,46 +12,30 @@ require 'setup.php';
// set the repo username and month to get the report for // set the repo username and month to get the report for
echo "Enter username for report: "; echo "Enter username for report: ";
$name = trim(fgets(STDIN)); // read from stdin $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"; echo "Enter month for report (0 = this, 1 = last, ...): ";
// Build a crazy id to number lookup table $ago = (int)(trim(fgets(STDIN))); // read from stdin
// https://github.com/go-gitea/gitea/issues/8513 $date_start = date('Y-m-01', strtotime("now -$ago month"));
foreach ($repo->getIssues() as $issue) { $date_end = date('Y-m-t', strtotime("now -$ago month"));
$issueNumbers[$issue->id] = $issue->number;
} $date = date('Y-m', strtotime("now -$ago month"));
foreach ($repo->getPulls() as $pull) { echo "Generateing report for {$repo->user}/{$repo->repo} of time spent between $date_start - $date_end by $name...\n";
$issue = $repo->getIssue($pull->number);
$issueNumbers[$issue->id] = $issue->number;
}
foreach ($repo->getIssues(['state' => 'closed']) as $issue) {
$issueNumbers[$issue->id] = $issue->number;
}
foreach ($repo->getPulls(['state' => 'closed']) as $pull) {
$issue = $repo->getIssue($pull->number);
$issueNumbers[$issue->id] = $issue->number;
}
// process and sum up all the times by issue number // process and sum up all the times by issue number
// (not ID as retrned by API) // (not ID as retrned by API)
$totals = []; $totals = [];
foreach ($repo->getTimesByUsername($name) as $time) { foreach ($repo->getTimesByUsername($name,new \DateTime("{$date_start} 00:00:00") , new \DateTime("{$date_end} 23:59:59")) as $time) {
// check the month
if ($date == date('Y-m', strtotime($time->created))) {
// get the issue number
$number = $issueNumbers[$time->issue_id];
// if we've not already got a total for this issue // if we've not already got a total for this issue
// then create the entry, looking up issue title // then create the entry, looking up issue title
if (!isset($totals[$number])) { if (!isset($totals[$time->issue->number])) {
$issue = $repo->getIssue($number); $totals[$time->issue->number] = [
$totals[$number] = [ 'id' => $time->issue->number,
'id' => $number, 'name' => $time->issue->title,
'name' => $issue->title,
'time' => 0, 'time' => 0,
]; ];
} }
// add the time to the total // add the time to the total
$totals[$number]['time'] += $time->time; $totals[$time->issue->number]['time'] += $time->time;
}
} }
// helper to format seconds into H:M:S format // helper to format seconds into H:M:S format