new time report example
This commit is contained in:
parent
7fbdf618e8
commit
5352a3ea37
58
src/time_report.php
Executable file
58
src/time_report.php
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
/*******************************************************
|
||||||
|
* Creats a csv report of times spend on issues for
|
||||||
|
* a specific month of a specific user.
|
||||||
|
********************************************************/
|
||||||
|
|
||||||
|
// load the config, create the connection and load the repo sepcified on the cmd line args
|
||||||
|
// we will then have $client and $repo available
|
||||||
|
require('setup.php');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
$name='jhodges';
|
||||||
|
$date='2019-10';
|
||||||
|
|
||||||
|
$sums=[];
|
||||||
|
foreach($repo->getTimesByUsername($name) as $time){
|
||||||
|
if($date==date('Y-m',strtotime($time->created))){
|
||||||
|
$number=$issueNumbers[$time->issue_id];
|
||||||
|
if(!isset($sums[$number])){
|
||||||
|
$issue=$repo->getIssue($number);
|
||||||
|
$sums[$number]=[
|
||||||
|
'id'=>$number,
|
||||||
|
'name'=>$issue->title,
|
||||||
|
'time'=>0
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$sums[$number]['time']+=$time->time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_time($t){
|
||||||
|
return sprintf('%02d:%02d:%02d', floor($t/3600), ($t/60)%60, $t%60);
|
||||||
|
}
|
||||||
|
|
||||||
|
$f=fopen('report.csv','w');
|
||||||
|
fputcsv($f,['id','title','time']);
|
||||||
|
foreach($sums as $id=>$data){
|
||||||
|
$data['time']=format_time($data['time']);
|
||||||
|
fputcsv($f,$data);
|
||||||
|
}
|
||||||
|
fclose($f);
|
||||||
|
echo "Saved as report.csv\n";
|
Loading…
Reference in New Issue
Block a user