Skip to content

Commit 4ad5713

Browse files
committed
added csv, labels filtering, new config and first steps towards merge requests
1 parent 825c20d commit 4ad5713

22 files changed

+873
-294
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"illuminate/support": "^5.4",
1515
"nesbot/carbon": "^1.22",
1616
"symfony/yaml": "^3.2",
17-
"symfony/process": "^3.2"
17+
"symfony/process": "^3.2",
18+
"league/csv": "^8.2"
1819
},
1920
"autoload": {
2021
"psr-4": {

composer.lock

Lines changed: 59 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ gtt report ["namespace/project"] [issue_id]
5050
gtt report:month ["2017-03"] ["namespace/project"]
5151
gtt report:day ["2017-03-01"] ["namespace/project"]
5252
53+
# timeframe
54+
git report --from="2017-03-01" --to="2017-04-01"
55+
5356
# include closed issues
5457
gtt report --closed=true
5558
@@ -65,14 +68,21 @@ gtt report --date_format="d.m.Y H:i:s"
6568
# overwrite the default columns or the columns stored in your config
6669
gtt report --columns=iid --columns=title --columns=estimation
6770
68-
# only include the given labels in the results, overwrites the includeLabels stored in your config file
71+
# only include issues and merge requests that have the following labels, overwrites the includeByLabels store in your config
72+
gtt report --include_by_labels=critical --include_by_labels=important
73+
74+
# exclude issues and merge requests that have the following labels, overwrites the excludeByLabels store in your config
75+
gtt report --exclude_by_labels=wont-fix --exclude_by_labels=ignore
76+
77+
# only include the given labels in the results, overwrites the includeLabels stored in your config
6978
gtt report --include_labels=pending --include_labels=approved
7079
71-
# exclude the given labels from the results, overwrites the excludeLabels stored in your config file
80+
# exclude the given labels from the results, overwrites the excludeLabels stored in your config
7281
gtt report --exclude_labels=bug --exclude_labels=feature
7382
74-
# choose a different output than a stdout table (csv & json coming soon)
83+
# choose a different output than a stdout table (json coming soon)
7584
gtt report --output=markdown --file=filename.md
85+
gtt report --output=csv --file=filename.csv
7686
```
7787

7888
#### time tracking
@@ -96,13 +106,14 @@ project: namespace/projectname
96106
# include closed by default
97107
closed: true
98108
99-
# default milestone
109+
# default milestone to filter issues by
100110
milestone: milestone_name
101111
102112
# hours per day
103113
hoursPerDay: 8
104114
105-
# columns
115+
# columns to include in the report
116+
# available columns: id, iid, title,
106117
columns:
107118
- iid
108119
- title
@@ -114,6 +125,16 @@ dateFormat: Y-m-d H:i:s
114125
# default output
115126
output: markdown
116127
128+
# exclude issues and merge requests that have the following labels
129+
excludeByLabels:
130+
- wont-fix
131+
- ignore
132+
133+
# only include issues and merge request that have the following labels
134+
includeByLabels:
135+
- critical
136+
- important
137+
117138
# exclude the following labels in the results
118139
excludeLabels:
119140
- bug
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
use Gitlab\Api\AbstractApi;
88

9-
class TimeStats extends AbstractApi
9+
/**
10+
* Class TimeStats
11+
* @package kriskbx\gtt\Api
12+
*/
13+
class IssueTimeStats extends AbstractApi
1014
{
1115
/**
1216
* @param int $project_id

src/Api/Issues.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33

44
namespace kriskbx\gtt\Api;
55

6-
6+
/**
7+
* Class Issues
8+
* @package kriskbx\gtt\Api
9+
*/
710
class Issues extends \Gitlab\Api\Issues
811
{
912
/**
13+
* Overwriting the GitLab API package showComments function, because it doesn't
14+
* support pagination.
15+
*
1016
* @param int $project_id
1117
* @param int $issue_id
1218
* @param int $page
@@ -16,11 +22,12 @@ class Issues extends \Gitlab\Api\Issues
1622
*/
1723
public function showComments($project_id, $issue_id, $page = 1, $per_page = self::PER_PAGE)
1824
{
19-
$params = array_merge(array(
20-
'page' => $page,
25+
$params = [
26+
'page' => $page,
2127
'per_page' => $per_page
22-
));
28+
];
2329

24-
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)).'/notes', $params);
30+
return $this->get($this->getProjectPath($project_id, 'issues/' . $this->encodePath($issue_id)) . '/notes',
31+
$params);
2532
}
2633
}

src/Api/MergeRequestTimeStats.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
namespace kriskbx\gtt\Api;
5+
6+
7+
use Gitlab\Api\AbstractApi;
8+
9+
/**
10+
* Class TimeStats
11+
* @package kriskbx\gtt\Api
12+
*/
13+
class MergeRequestTimeStats extends AbstractApi
14+
{
15+
/**
16+
* @param int $project_id
17+
* @param int $issue_id
18+
*
19+
* @return mixed
20+
*/
21+
public function getTimeStats($project_id, $issue_id)
22+
{
23+
return $this->get($this->getProjectPath($project_id,
24+
'merge_request/' . $this->encodePath($issue_id)) . '/time_stats');
25+
}
26+
}

src/Api/MergeRequests.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
4+
namespace kriskbx\gtt\Api;
5+
6+
7+
class MergeRequests extends \Gitlab\Api\MergeRequests
8+
{
9+
/**
10+
* Overwriting the GitLab API package showComments function, because it doesn't
11+
* support pagination.
12+
*
13+
* @param int $project_id
14+
* @param int $mr_id
15+
* @param int $page
16+
* @param int $per_page
17+
*
18+
* @return mixed
19+
*/
20+
public function showComments($project_id, $mr_id, $page = 1, $per_page = self::PER_PAGE)
21+
{
22+
$params = [
23+
'page' => $page,
24+
'per_page' => $per_page
25+
];
26+
27+
return $this->get($this->getProjectPath($project_id,
28+
'merge_request/' . $this->encodePath($mr_id) . '/comments'), $params);
29+
}
30+
}

src/Collection/TimesCollection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
use Illuminate\Support\Collection;
88
use kriskbx\gtt\Time;
99

10+
/**
11+
* Class TimesCollection
12+
*
13+
* Time should be rendered differently, so we extend the base Collection and implement our own toString method.
14+
* @package kriskbx\gtt\Collection
15+
*/
1016
class TimesCollection extends Collection
1117
{
1218
/**

src/Commands/BaseCommand.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
namespace kriskbx\gtt\Commands;
55

66
use Gitlab\Client;
7-
use kriskbx\gtt\Output\Csv;
8-
use kriskbx\gtt\Output\Markdown;
7+
use kriskbx\gtt\Config\Config;
8+
use kriskbx\gtt\Output\CsvOutput;
9+
use kriskbx\gtt\Output\MarkdownOutput;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\ArrayInput;
1112
use Symfony\Component\Console\Input\InputInterface;
@@ -16,7 +17,7 @@ class BaseCommand extends Command
1617
{
1718
/**
1819
* Config array.
19-
* @var array
20+
* @var Config
2021
*/
2122
protected $config;
2223

@@ -31,16 +32,17 @@ class BaseCommand extends Command
3132
* @var array
3233
*/
3334
protected $outputs = [
34-
'markdown' => Markdown::class
35+
'markdown' => MarkdownOutput::class,
36+
'csv' => CsvOutput::class
3537
];
3638

3739
/**
3840
* ReportMonth constructor.
3941
*
4042
* @param Client $client
41-
* @param array $config
43+
* @param Config $config
4244
*/
43-
public function __construct(Client $client, array $config)
45+
public function __construct(Client $client, Config $config)
4446
{
4547
$this->config = $config;
4648
$this->client = $client;
@@ -69,7 +71,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
6971
*/
7072
protected function configure()
7173
{
72-
$this->addOption('closed', null, InputOption::VALUE_REQUIRED, 'Include closed issues, defaults to false')
74+
$this->addOption('closed', null, InputOption::VALUE_REQUIRED,
75+
'Include closed issues and merged merge requests, defaults to false')
7376
->addOption('columns', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
7477
'Include the given columns in the report')
7578
->addOption('date_format', null, InputOption::VALUE_REQUIRED, 'Date format')
@@ -80,10 +83,14 @@ protected function configure()
8083
null)
8184
->addOption('file', null, InputOption::VALUE_OPTIONAL,
8285
'If output supports file-saving, specify the path to the file', null)
86+
->addOption('include_by_labels', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
87+
'Include only issues and merge requests by the given labels', null)
8388
->addOption('include_labels', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
8489
'Include only the given labels in the result', null)
8590
->addOption('exclude_labels', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
86-
'Exclude the given labels from the result', null);
91+
'Exclude the given labels from the result', null)
92+
->addOption('exclude_by_labels', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
93+
'Exclude issues and merge requests by the given labels', null);;
8794
}
8895

8996
/**
@@ -118,9 +125,15 @@ protected function getDefaultArguments(InputInterface $input)
118125
if ($input->getOption('include_labels')) {
119126
$arguments['--include_labels'] = $input->getOption('include_labels');
120127
}
128+
if ($input->getOption('include_by_labels')) {
129+
$arguments['--include_by_labels'] = $input->getOption('include_by_labels');
130+
}
121131
if ($input->getOption('exclude_labels')) {
122132
$arguments['--exclude_labels'] = $input->getOption('exclude_labels');
123133
}
134+
if ($input->getOption('exclude_by_labels')) {
135+
$arguments['--exclude_by_labels'] = $input->getOption('exclude_by_labels');
136+
}
124137

125138
return $arguments;
126139
}

0 commit comments

Comments
 (0)