update reports
This commit is contained in:
parent
100b941b08
commit
7e7ea149d8
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/src/config.php
|
||||
/vendor/
|
||||
report.csv
|
||||
|
@ -8,7 +8,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"jhodges/giteabot": "~1.2.0"
|
||||
"jhodges/giteabot": "dev-master"
|
||||
},
|
||||
"repositories": {
|
||||
"repo-name": {
|
||||
|
12
composer.lock
generated
12
composer.lock
generated
@ -4,15 +4,15 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "8e21cb9a16c0817b84a9643dc47c1a78",
|
||||
"content-hash": "9128b5f63e7fb3651cfc3548f2267d6d",
|
||||
"packages": [
|
||||
{
|
||||
"name": "jhodges/giteabot",
|
||||
"version": "v1.2.1",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://git.jhodges.co.uk/jhodges/GiteaBot",
|
||||
"reference": "a2c44392b2b4eede6be4b132e55e3479232fda93"
|
||||
"reference": "83eea50cf9bce925075b9e8c66906f9c2c3a249f"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@ -30,13 +30,15 @@
|
||||
}
|
||||
],
|
||||
"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": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"stability-flags": {
|
||||
"jhodges/giteabot": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
|
18
src/issue_report.php
Executable file
18
src/issue_report.php
Executable 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";
|
@ -3,6 +3,7 @@
|
||||
/*
|
||||
* Creats a csv report of times spend on issues for
|
||||
* 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
|
||||
|
68
src/time_report_new.php
Executable file
68
src/time_report_new.php
Executable 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";
|
Loading…
Reference in New Issue
Block a user