Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 5ea309a

Browse files
committed
added time format options and estimate, time_spent columns
1 parent 9b7d2ea commit 5ea309a

File tree

11 files changed

+152
-59
lines changed

11 files changed

+152
-59
lines changed

readme.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ gtt report --milestone=milestone_name
6565
# overwrite the default date format or the date format stored in your config
6666
gtt report --date_format="d.m.Y H:i:s"
6767
68+
# overwrite the default time format
69+
gtt report --time_format="[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]"
70+
6871
# overwrite the default columns or the columns stored in your config
6972
gtt report --columns=iid --columns=title --columns=estimation
7073
@@ -113,7 +116,8 @@ milestone: milestone_name
113116
hoursPerDay: 8
114117
115118
# columns to include in the report
116-
# available columns: id, iid, title, project_id, description, labels, milestone, assignee, author, closed, updated_at, created_at, state
119+
# available columns: id, iid, title, project_id, description, labels, milestone,
120+
# assignee, author, closed, updated_at, created_at, state
117121
columns:
118122
- iid
119123
- title
@@ -122,6 +126,15 @@ columns:
122126
# date format
123127
dateFormat: Y-m-d H:i:s
124128
129+
# time format
130+
# [%sign], [%days], [%hours], [%minutes], [%seconds]
131+
# -> prints out the raw data
132+
# [%days>string], [%hours>string], [%minutes>string], [%seconds>string]
133+
# -> is a conditional and prints out the data and appends the given string if the data is greater than zero
134+
# [%Days], [%Hours], [%Minutes], ...
135+
# -> uppercase adds leading zeros.
136+
timeFormat: [%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]
137+
125138
# default output
126139
output: markdown
127140

src/Collection/TimesCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function displayUser(Collection $times, $user, array $params)
5858
{
5959
$totalTime = Time::humanReadable($times->reduce(function ($carry, Time $item) {
6060
return $carry + (int)$item->getSeconds();
61-
}));
61+
}), @$params['hoursPerDay'], @$params['timeFormat']);
6262

6363
return "{$params['beforeHeadline']}$user: {$totalTime}{$params['afterHeadline']}{$params['break']}";
6464
}

src/Commands/BaseCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ protected function configure()
7676
->addOption('columns', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
7777
'Include the given columns in the report')
7878
->addOption('date_format', null, InputOption::VALUE_REQUIRED, 'Date format')
79+
->addOption('time_format', null, InputOption::VALUE_REQUIRED, 'Time format')
7980
->addOption('user', null, InputOption::VALUE_OPTIONAL, 'Filter times by the given user', null)
8081
->addOption('milestone', null, InputOption::VALUE_OPTIONAL, 'Filter times by the given milestone', null)
8182
->addOption('output', null, InputOption::VALUE_OPTIONAL,
@@ -113,6 +114,9 @@ protected function getDefaultArguments(InputInterface $input)
113114
if ($input->getOption('date_format')) {
114115
$arguments['--date_format'] = $input->getOption('date_format');
115116
}
117+
if ($input->getOption('time_format')) {
118+
$arguments['--time_format'] = $input->getOption('time_format');
119+
}
116120
if ($input->getOption('user')) {
117121
$arguments['--user'] = $input->getOption('user');
118122
}

src/Commands/ReportProject.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use kriskbx\gtt\MergeRequest;
1111
use kriskbx\gtt\Output\TableOutput;
1212
use kriskbx\gtt\Project;
13+
use kriskbx\gtt\Time;
1314
use Symfony\Component\Console\Helper\ProgressBar;
1415
use Symfony\Component\Console\Input\InputArgument;
1516
use Symfony\Component\Console\Input\InputInterface;
@@ -72,7 +73,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7273
$includeLabels,
7374
$excludeLabels,
7475
$includeByLabels,
75-
$excludeByLabels
76+
$excludeByLabels,
77+
$timeFormat
7678
) = $this->getConfiguration($input);
7779

7880
// Get project
@@ -106,7 +108,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
106108
}
107109

108110
// Set time records in issues
109-
$issues = $this->setTimesInIssues($output, $issues, $from, $to, $user);
111+
$issues = $this->setTimesInIssues($output, $issues, $from, $to, $user, $this->config['hoursPerDay'],
112+
$timeFormat);
110113
// $mergeRequests = $this->setTimesInIssues($output, $mergeRequests, $from, $to, $user);
111114

112115
// Put everything out there!
@@ -250,22 +253,30 @@ protected function getMergeRequests(
250253
*
251254
* @param OutputInterface $output
252255
* @param Collection $issues
253-
* @param string $user
254256
* @param Carbon $from
255257
* @param Carbon $to
256258
*
257-
* @return Collection
259+
* @param string $user
260+
* @param int $hoursPerDay
261+
* @param string $timeFormat
258262
*
259-
* @throws \Exception
263+
* @return Collection
260264
*/
261-
protected function setTimesInIssues(OutputInterface $output, Collection $issues, Carbon $from, Carbon $to, $user)
262-
{
265+
protected function setTimesInIssues(
266+
OutputInterface $output,
267+
Collection $issues,
268+
Carbon $from,
269+
Carbon $to,
270+
$user,
271+
$hoursPerDay = 8,
272+
$timeFormat = Time::TIME_FORMAT
273+
) {
263274
$progress = new ProgressBar($output, $issues->count());
264275
$progress->setFormat('* Processing issues... %current%/%max% [%bar%] %percent:3s%% | <fg=green>%remaining%</>');
265276

266277
// Add times to each Issue
267-
$issues = $issues->map(function (Issue $issue) use ($from, $to, $user, &$progress) {
268-
$issue->setTimes($from, $to, $user);
278+
$issues = $issues->map(function (Issue $issue) use ($from, $to, $user, &$progress, $hoursPerDay, $timeFormat) {
279+
$issue->setTimes($from, $to, $user, $hoursPerDay, $timeFormat);
269280

270281
$progress->advance();
271282

@@ -305,6 +316,7 @@ protected function getConfiguration(InputInterface $input)
305316
$excludeLabels = $input->getOption('exclude_labels') === null ? $this->config['excludeLabels'] : $input->getOption('exclude_labels');
306317
$includeByLabels = $input->getOption('include_by_labels') === null ? $this->config['includeByLabels'] : $input->getOption('include_by_labels');
307318
$excludeByLabels = $input->getOption('exclude_by_labels') === null ? $this->config['excludeByLabels'] : $input->getOption('exclude_by_labels');
319+
$timeFormat = $this->config['timeFormat'] = $input->getOption('time_format') === null ? $this->config['timeFormat'] : $input->getOption('time_format');
308320

309321
return [
310322
$from,
@@ -320,7 +332,8 @@ protected function getConfiguration(InputInterface $input)
320332
$includeLabels,
321333
$excludeLabels,
322334
$includeByLabels,
323-
$excludeByLabels
335+
$excludeByLabels,
336+
$timeFormat
324337
];
325338
}
326339

src/Config/Config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Exception;
88
use Illuminate\Contracts\Support\Arrayable;
9+
use kriskbx\gtt\Time;
910
use Symfony\Component\Yaml\Yaml;
1011

1112
/**
@@ -131,6 +132,7 @@ protected function defaults()
131132
'hoursPerDay' => @$this->config['hoursPerDay'] ?: 8,
132133
'columns' => @$this->config['columns'] ?: ['iid', 'title', 'estimation'],
133134
'dateFormat' => @$this->config['dateFormat'] ?: 'd.m.Y H:i',
135+
'timeFormat' => @$this->config['timeFormat'] ?: Time::TIME_FORMAT,
134136
'excludeByLabels' => @$this->config['excludeByLabels'] ?: [],
135137
'includeByLabels' => @$this->config['includeByLabels'] ?: [],
136138
'excludeLabels' => @$this->config['excludeLabels'] ?: [],

src/Estimation.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Estimation implements Arrayable, \ArrayAccess
1919

2020
protected $totalTimeSpent;
2121

22-
protected $humanTimeEstimate;
22+
protected $hoursPerDay;
2323

24-
protected $humanTotalTimeSpent;
24+
protected $timeFormat;
2525

2626
/**
2727
* @return mixed
@@ -44,31 +44,31 @@ public function getTotalTimeSpent()
4444
*/
4545
public function getHumanTimeEstimate()
4646
{
47-
return $this->humanTimeEstimate;
47+
return Time::humanReadable($this->timeEstimate, $this->hoursPerDay, $this->timeFormat);
4848
}
4949

5050
/**
5151
* @return mixed
5252
*/
5353
public function getHumanTotalTimeSpent()
5454
{
55-
return $this->humanTotalTimeSpent;
55+
return Time::humanReadable($this->totalTimeSpent, $this->hoursPerDay, $this->timeFormat);
5656
}
5757

5858
/**
5959
* Estimation constructor.
6060
*
6161
* @param $timeEstimate
6262
* @param $totalTimeSpent
63-
* @param $humanTimeEstimate
64-
* @param $humanTotalTimeSpent
63+
* @param int $hoursPerDay
64+
* @param string $timeFormat
6565
*/
66-
public function __construct($timeEstimate, $totalTimeSpent, $humanTimeEstimate, $humanTotalTimeSpent)
66+
public function __construct($timeEstimate, $totalTimeSpent, $hoursPerDay = 8, $timeFormat = Time::TIME_FORMAT)
6767
{
68-
$this->timeEstimate = $timeEstimate;
69-
$this->totalTimeSpent = $totalTimeSpent;
70-
$this->humanTimeEstimate = $humanTimeEstimate;
71-
$this->humanTotalTimeSpent = $humanTotalTimeSpent;
68+
$this->timeEstimate = $timeEstimate;
69+
$this->totalTimeSpent = $totalTimeSpent;
70+
$this->hoursPerDay = $hoursPerDay;
71+
$this->timeFormat = $timeFormat;
7272
}
7373

7474
/**
@@ -95,7 +95,7 @@ public function toString($params = [])
9595
*/
9696
protected function displayEstimation()
9797
{
98-
return $this->humanTimeEstimate . ' / ' . $this->humanTotalTimeSpent;
98+
return $this->getHumanTimeEstimate() . ' / ' . $this->getHumanTotalTimeSpent();
9999
}
100100

101101
/**
@@ -110,8 +110,8 @@ public static function fromArray(array $data)
110110
return new static(
111111
@$data['time_estimate'],
112112
@$data['total_time_spent'],
113-
@$data['human_time_estimate'],
114-
@$data['human_total_time_spent']
113+
@$data['hours_per_day'],
114+
@$data['time_format']
115115
);
116116
}
117117
}

src/Issue.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,28 @@ public function getId()
161161
return $this->id;
162162
}
163163

164+
public function getEstimate()
165+
{
166+
return $this->estimation->getHumanTimeEstimate() ?: 'N/A';
167+
}
168+
169+
public function getTimeSpent()
170+
{
171+
return $this->estimation->getHumanTotalTimeSpent();
172+
}
173+
164174
/**
165175
* Set time stats (estimated, spent)
176+
*
177+
* @param int $hoursPerDay
178+
* @param string $timeFormat
166179
*/
167-
public function setTimeStats()
180+
public function setTimeStats($hoursPerDay = 8, $timeFormat = Time::TIME_FORMAT)
168181
{
169-
$stats = (new IssueTimeStats($this->client))->getTimeStats($this->project_id, $this->iid);
170-
$this->estimation = Estimation::fromArray($stats);
182+
$stats = (new IssueTimeStats($this->client))->getTimeStats($this->project_id, $this->iid);
183+
$stats['hours_per_day'] = $hoursPerDay;
184+
$stats['time_format'] = $timeFormat;
185+
$this->estimation = Estimation::fromArray($stats);
171186
}
172187

173188
/**

src/Output/MarkdownOutput.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function render(Collection $issues, $title, array $params)
4646
$this->contents .= "\n| " . $issue->toString($params) . " |";
4747
});
4848

49-
$this->total();
49+
$this->total($params);
5050

5151
$this->write($this->contents, $this->file);
5252

@@ -63,14 +63,19 @@ protected function cleanUp()
6363

6464
/**
6565
* Set total times.
66+
*
67+
* @param array $params
6668
*/
67-
protected function total()
69+
protected function total(array $params)
6870
{
69-
$subString = "* **Total spent:** " . Time::humanReadable($this->totalTime) . "\n";
70-
$subString .= "* **Total estimated:** " . Time::humanReadable($this->totalEstimate) . "\n";
71-
72-
collect($this->totalTimeByUser)->each(function ($time, $user) use (&$subString) {
73-
$subString .= "* **{$user}:** " . Time::humanReadable($time) . "\n";
71+
$subString = "* **Total spent:** " .
72+
Time::humanReadable($this->totalTime, @$params['hoursPerDay'], @$params['timeFormat']) . "\n";
73+
$subString .= "* **Total estimated:** " .
74+
Time::humanReadable($this->totalEstimate, @$params['hoursPerDay'], @$params['timeFormat']) . "\n";
75+
76+
collect($this->totalTimeByUser)->each(function ($time, $user) use (&$subString, $params) {
77+
$subString .= "* **{$user}:** " .
78+
Time::humanReadable($time, @$params['hoursPerDay'], @$params['timeFormat']) . "\n";
7479
});
7580

7681
$this->contents = $subString . "\n\n" . $this->contents;

src/Output/TableOutput.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function render(Collection $issues, $title, array $params)
6565
$this->output->writeln("<fg=black;bg=blue> {$title} </>");
6666
$this->output->writeln('');
6767

68-
$this->total();
68+
$this->total($params);
6969
$this->table->render();
7070

7171
$this->output->writeln('');
@@ -123,14 +123,19 @@ protected function estimationBar(Estimation $estimation, $params = [])
123123

124124
/**
125125
* Print out total stats.
126+
*
127+
* @param array $params
126128
*/
127-
protected function total()
129+
protected function total(array $params)
128130
{
129-
$string = "* <fg=blue>Total spent:</> " . Time::humanReadable($this->totalTime) . "\n";
130-
$string .= "* <fg=blue>Total estimate:</> " . Time::humanReadable($this->totalEstimate) . "\n\n";
131-
132-
collect($this->totalTimeByUser)->each(function ($time, $user) use (&$string) {
133-
$string .= "* <fg=blue>{$user}:</> " . Time::humanReadable($time) . "\n";
131+
$string = "* <fg=blue>Total spent:</> " .
132+
Time::humanReadable($this->totalTime, @$params['hoursPerDay'], @$params['timeFormat']) . "\n";
133+
$string .= "* <fg=blue>Total estimate:</> " .
134+
Time::humanReadable($this->totalEstimate, @$params['hoursPerDay'], @$params['timeFormat']) . "\n\n";
135+
136+
collect($this->totalTimeByUser)->each(function ($time, $user) use (&$string, $params) {
137+
$string .= "* <fg=blue>{$user}:</> "
138+
. Time::humanReadable($time, @$params['hoursPerDay'], @$params['timeFormat']) . "\n";
134139
});
135140

136141
$this->output->write($string . "\n");

0 commit comments

Comments
 (0)