update to use new api, much cleaner code now :)
This commit is contained in:
parent
e869bc2d8e
commit
100b941b08
@ -12,46 +12,30 @@ 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
|
||||
// https://github.com/go-gitea/gitea/issues/8513
|
||||
foreach ($repo->getIssues() as $issue) {
|
||||
$issueNumbers[$issue->id] = $issue->number;
|
||||
}
|
||||
foreach ($repo->getPulls() as $pull) {
|
||||
$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;
|
||||
}
|
||||
|
||||
echo "Enter month for report (0 = this, 1 = last, ...): ";
|
||||
$ago = (int)(trim(fgets(STDIN))); // read from stdin
|
||||
$date_start = date('Y-m-01', strtotime("now -$ago month"));
|
||||
$date_end = date('Y-m-t', strtotime("now -$ago month"));
|
||||
|
||||
$date = date('Y-m', strtotime("now -$ago month"));
|
||||
echo "Generateing report for {$repo->user}/{$repo->repo} of time spent between $date_start - $date_end by $name...\n";
|
||||
|
||||
// process and sum up all the times by issue number
|
||||
// (not ID as retrned by API)
|
||||
$totals = [];
|
||||
foreach ($repo->getTimesByUsername($name) as $time) {
|
||||
// check the month
|
||||
if ($date == date('Y-m', strtotime($time->created))) {
|
||||
// get the issue number
|
||||
$number = $issueNumbers[$time->issue_id];
|
||||
foreach ($repo->getTimesByUsername($name,new \DateTime("{$date_start} 00:00:00") , new \DateTime("{$date_end} 23:59:59")) as $time) {
|
||||
// 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);
|
||||
$totals[$number] = [
|
||||
'id' => $number,
|
||||
'name' => $issue->title,
|
||||
if (!isset($totals[$time->issue->number])) {
|
||||
$totals[$time->issue->number] = [
|
||||
'id' => $time->issue->number,
|
||||
'name' => $time->issue->title,
|
||||
'time' => 0,
|
||||
];
|
||||
}
|
||||
// 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
|
||||
|
Loading…
Reference in New Issue
Block a user