1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Jira-CLI library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/jira-cli |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\JiraCLI\Command; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
class VersionsCommand extends AbstractCommand |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
protected function configure() |
24
|
|
|
{ |
25
|
|
|
$this |
26
|
|
|
->setName('versions') |
27
|
|
|
->setDescription('Shows version usage across projects'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
34
|
|
|
{ |
35
|
|
|
$versions = array(); |
36
|
|
|
|
37
|
|
|
$this->io->write('Getting projects ... '); |
38
|
|
|
$project_keys = $this->getProjectKeys(); |
39
|
|
|
$this->io->writeln('done (' . count($project_keys) . ' found)'); |
40
|
|
|
|
41
|
|
|
foreach ( $project_keys as $project_key ) { |
42
|
|
|
$this->io->write('Getting project <info>' . $project_key . '</info> versions ... '); |
43
|
|
|
$project_versions = $this->getProjectVersionsRaw($project_key); |
44
|
|
|
$this->io->writeln('done (' . count($project_versions) . ' found)'); |
45
|
|
|
|
46
|
|
|
foreach ( $project_versions as $project_version_data ) { |
47
|
|
|
$project_version = $project_version_data['name']; |
48
|
|
|
|
49
|
|
|
// Interested only in final releases. |
50
|
|
|
if ( strpos($project_version, '-') === false ) { |
51
|
|
|
$versions[$project_version] = true; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$versions = array_keys($versions); |
57
|
|
|
usort($versions, 'version_compare'); |
58
|
|
|
|
59
|
|
|
$this->io->writeln(array('', 'Versions:')); |
60
|
|
|
|
61
|
|
|
foreach ( $versions as $version ) { |
62
|
|
|
$this->io->writeln(' * ' . $version); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Returns raw project versions. |
68
|
|
|
* |
69
|
|
|
* @param string $project_key Project key. |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
protected function getProjectVersionsRaw($project_key) |
74
|
|
|
{ |
75
|
|
|
$cache_key = 'project_versions_raw[' . $project_key . ']'; |
76
|
|
|
$cached_value = $this->cache->fetch($cache_key); |
77
|
|
|
|
78
|
|
|
if ( $cached_value === false ) { |
79
|
|
|
$cached_value = $this->jiraApi->getVersions($project_key); |
80
|
|
|
$this->cache->save($cache_key, $cached_value, 2592000); // Cache for 1 month. |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $cached_value; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|