From 7e7ea149d83396260217a772f580b995f0f97550 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 2 Feb 2020 15:12:47 +0000 Subject: [PATCH] update reports --- .gitignore | 1 + composer.json | 2 +- composer.lock | 12 +++++--- src/issue_report.php | 18 +++++++++++ src/time_report.php | 1 + src/time_report_new.php | 68 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 6 deletions(-) create mode 100755 src/issue_report.php create mode 100755 src/time_report_new.php diff --git a/.gitignore b/.gitignore index 011fdab..b760f71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /src/config.php /vendor/ +report.csv diff --git a/composer.json b/composer.json index 0ad7839..7b6318e 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ } ], "require": { - "jhodges/giteabot": "~1.2.0" + "jhodges/giteabot": "dev-master" }, "repositories": { "repo-name": { diff --git a/composer.lock b/composer.lock index dd7a3e0..a704983 100644 --- a/composer.lock +++ b/composer.lock @@ -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": [], diff --git a/src/issue_report.php b/src/issue_report.php new file mode 100755 index 0000000..b30d59e --- /dev/null +++ b/src/issue_report.php @@ -0,0 +1,18 @@ +#!/usr/bin/php +getIssues() as $issue){ + print_r($issue); + fputcsv($f, [$issue->number,$issue->created_at,$issue->title] ); +} +fclose($f); +echo "Saved as report.csv\n"; diff --git a/src/time_report.php b/src/time_report.php index 3b8c757..e975f7b 100755 --- a/src/time_report.php +++ b/src/time_report.php @@ -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 diff --git a/src/time_report_new.php b/src/time_report_new.php new file mode 100755 index 0000000..2855b26 --- /dev/null +++ b/src/time_report_new.php @@ -0,0 +1,68 @@ +#!/usr/bin/php +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";