update reports

This commit is contained in:
James 2020-02-02 15:12:47 +00:00
parent 100b941b08
commit 7e7ea149d8
6 changed files with 96 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/src/config.php /src/config.php
/vendor/ /vendor/
report.csv

View File

@ -8,7 +8,7 @@
} }
], ],
"require": { "require": {
"jhodges/giteabot": "~1.2.0" "jhodges/giteabot": "dev-master"
}, },
"repositories": { "repositories": {
"repo-name": { "repo-name": {

12
composer.lock generated
View File

@ -4,15 +4,15 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "8e21cb9a16c0817b84a9643dc47c1a78", "content-hash": "9128b5f63e7fb3651cfc3548f2267d6d",
"packages": [ "packages": [
{ {
"name": "jhodges/giteabot", "name": "jhodges/giteabot",
"version": "v1.2.1", "version": "dev-master",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.jhodges.co.uk/jhodges/GiteaBot", "url": "https://git.jhodges.co.uk/jhodges/GiteaBot",
"reference": "a2c44392b2b4eede6be4b132e55e3479232fda93" "reference": "83eea50cf9bce925075b9e8c66906f9c2c3a249f"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -30,13 +30,15 @@
} }
], ],
"description": "Simple PHP library to interface with Gitea API", "description": "Simple PHP library to interface with Gitea API",
"time": "2019-09-07T08:43:48+00:00" "time": "2020-02-02T15:09:10+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": {
"jhodges/giteabot": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": [],

18
src/issue_report.php Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/php
<?php
/*
* Creats a csv report of open issues
*/
// 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';
$f = fopen('report.csv', 'w');
fputcsv($f, ['#','Date','Title']);
foreach ($repo->getIssues() as $issue){
print_r($issue);
fputcsv($f, [$issue->number,$issue->created_at,$issue->title] );
}
fclose($f);
echo "Saved as report.csv\n";

View File

@ -3,6 +3,7 @@
/* /*
* Creats a csv report of times spend on issues for * Creats a csv report of times spend on issues for
* a specific month of a specific user. * a specific month of a specific user.
* BROKEN: not got perms since latest gitea
*/ */
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args

68
src/time_report_new.php Executable file
View File

@ -0,0 +1,68 @@
#!/usr/bin/php
<?php
/*
* Creats a csv report of times spend on issues for
* a specific month of a specific user.
*/
require __DIR__.'/../vendor/autoload.php';
use JHodges\GiteaBot\Client;
$config = require __DIR__.'/config.php';
echo "Enter username for report: ";
$name = trim(fgets(STDIN)); // read from stdin
echo "Enter password: ";
$pass = trim(fgets(STDIN)); // read from stdin
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"));
echo "Generateing report of time spent between $date_start - $date_end by $name...\n";
//open connection and repo
$client = new Client($config['url'], $name, $pass, $debug=true);
// process and sum up all the times by issue number
// (not ID as retrned by API)
$totals = [];
foreach ($client->getCurrentUserTimes(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[$time->issue->repository->full_name][$time->issue->number])) {
$totals[$time->issue->repository->full_name][$time->issue->number] = [
'repo'=> $time->issue->repository->full_name,
'id' => $time->issue->number,
'name' => $time->issue->title,
'time' => 0,
];
}
// add the time to the total
$totals[$time->issue->repository->full_name][$time->issue->number]['time'] += $time->time;
}
// helper to format seconds into H:M:S format
function format_time($t)
{
return sprintf('%02d:%02d:%02d', floor($t / 3600), ($t / 60) % 60, $t % 60);
}
// save the report
$f = fopen('report.csv', 'w');
// ouput headers
fputcsv($f, ['Repo', 'ID', 'Description', 'Hours', 'H:M:S']);
// output data
foreach ($totals as $total){
foreach ($total as $id => $data) {
$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);
}
}
fclose($f);
echo "Saved as report.csv\n";