Skip to content

Commit 829e1ab

Browse files
committed
Show performed API request counter for each command in verbose mode
1 parent cfd7bb4 commit 829e1ab

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

src/JiraCLI/Command/AbstractCommand.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,23 @@ public function completeArgumentValues($argumentName, CompletionContext $context
101101
return $ret;
102102
}
103103

104+
/**
105+
* Shows statistics.
106+
*
107+
* @return void
108+
*/
109+
protected function showStatistics()
110+
{
111+
if ( !$this->io->isVerbose() ) {
112+
return;
113+
}
114+
115+
$request_count = $this->jiraApi->getRequestCount();
116+
117+
if ( $request_count ) {
118+
$this->io->writeln('===============');
119+
$this->io->writeln('API Requests Made: ' . $request_count);
120+
}
121+
}
122+
104123
}

src/JiraCLI/Command/BackportCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
104104
else {
105105
$this->showBackportableIssues($issues);
106106
}
107+
108+
$this->showStatistics();
107109
}
108110

109111
/**

src/JiraCLI/Command/ChangeLogCloneCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
180180
$linked_issue_key
181181
));
182182
}
183+
184+
$this->showStatistics();
183185
}
184186

185187
}

src/JiraCLI/Command/DownloadAttachmentCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7676
);
7777
$this->io->writeln('done');
7878
}
79+
80+
$this->showStatistics();
7981
}
8082

8183
/**

src/JiraCLI/Command/VersionsCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
6262
foreach ( $versions as $version ) {
6363
$this->io->writeln(' * ' . $version);
6464
}
65+
66+
$this->showStatistics();
6567
}
6668

6769
}

src/JiraCLI/JiraApi.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,39 @@ class JiraApi extends Api
2828
*/
2929
protected $cache;
3030

31+
/**
32+
* Request counter.
33+
*
34+
* @var integer
35+
*/
36+
protected $requestCounter = 0;
37+
38+
/**
39+
* @inheritDoc
40+
*/
41+
public function api(
42+
$method = self::REQUEST_GET,
43+
$url,
44+
$data = array(),
45+
$return_as_array = false,
46+
$is_file = false,
47+
$debug = false
48+
) {
49+
$this->requestCounter++;
50+
51+
return parent::api($method, $url, $data, $return_as_array, $is_file, $debug);
52+
}
53+
54+
/**
55+
* Returns request counter.
56+
*
57+
* @return integer
58+
*/
59+
public function getRequestCount()
60+
{
61+
return $this->requestCounter;
62+
}
63+
3164
/**
3265
* Sets cache.
3366
*

0 commit comments

Comments
 (0)