Skip to content

Commit 86f9129

Browse files
committed
Add stability to each PR, show next version
1 parent 251f30a commit 86f9129

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

src/Console/Command/ReleaseCommand.php

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ private function prepareRelease(Package $package, $branch, OutputInterface $outp
100100
$output->writeln($this->printPullRequest($pull));
101101
}
102102

103+
$this->io->section('Release');
104+
105+
if ($nextRelease === $currentRelease) {
106+
$this->io->warning('Release is not needed');
107+
} else {
108+
$this->io->success('Next release will be: '.$nextRelease);
109+
}
110+
103111
$this->io->section('Changelog');
104112

105113
$output->writeln($this->printRelease($currentRelease['tag_name'], $nextRelease, $package));
@@ -108,62 +116,61 @@ private function prepareRelease(Package $package, $branch, OutputInterface $outp
108116

109117
private function determineNextRelease($currentRelease, $pulls)
110118
{
111-
$nextRelease = null;
119+
$stability = 'stable';
112120
foreach ($pulls as $pull) {
113-
foreach ($pull['labels'] as $label) {
114-
if ('minor' === $label['name']) {
115-
$nextRelease = 'minor';
116-
break 2;
117-
} elseif ('patch' === $label['name']) {
118-
$nextRelease = 'patch';
121+
if (in_array($pull['stability'], array('minor', 'patch'))) {
122+
$stability = $pull['stability'];
123+
124+
if ('minor' === $pull['stability']) {
125+
break;
119126
}
120127
}
121128
}
122129

123-
if (empty($nextRelease)) {
124-
$this->io->warning('Release is not required');
125-
}
126-
127130
$parts = explode('.', $currentRelease['tag_name']);
128-
if ('minor' === $nextRelease) {
131+
if ('stable' === $stability) {
132+
return implode(array($parts[0], $parts[1], $parts[2]), '.');
133+
} elseif ('minor' === $stability) {
129134
return implode(array($parts[0], $parts[1] + 1, 0), '.');
130-
} elseif ('patch' === $nextRelease) {
135+
} elseif ('patch' === $stability) {
131136
return implode(array($parts[0], $parts[1], $parts[2] + 1), '.');
132137
}
133138
}
134139

135140
private function printPullRequest($pull)
136141
{
137-
$possibleLabels = array(
142+
$labelColors = array(
138143
'patch' => 'blue',
139144
'bug' => 'red',
140145
'docs' => 'yellow',
141146
'minor' => 'green',
142147
'pedantic' => 'cyan',
143148
);
149+
$stabilityColors = array(
150+
'patch' => 'blue',
151+
'minor' => 'green',
152+
'stable' => 'yellow',
153+
);
144154

145-
$requiredChangelog = false;
146-
$print = '<info>'.$pull['title'].'</info>';
155+
$print = '<fg=black;bg='.$stabilityColors[$pull['stability']].'>['.strtoupper($pull['stability']).']</>';
156+
$print .= ' <info>'.$pull['title'].'</info>';
147157
foreach ($pull['labels'] as $label) {
148-
if (!array_key_exists($label['name'], $possibleLabels)) {
158+
if (!array_key_exists($label['name'], $labelColors)) {
149159
$print .= ' <error>['.$label['name'].']</error>';
150160
} else {
151-
if (!in_array($label['name'], array('pedantic', 'docs'))) {
152-
$requiredChangelog = true;
153-
}
154-
$print .= ' <fg='.$possibleLabels[$label['name']].'>['.$label['name'].']</>';
161+
$print .= ' <fg='.$labelColors[$label['name']].'>['.$label['name'].']</>';
155162
}
156163
}
157164

158165
if (empty($pull['labels'])) {
159166
$print .= ' <fg=black;bg=yellow>[No labels]</>';
160167
}
161168

162-
if (!$pull['changelog'] && $requiredChangelog) {
169+
if (!$pull['changelog'] && 'stable' !== $pull['stability']) {
163170
$print .= ' <error>[Changelog not found]</error>';
164171
} elseif (!$pull['changelog']) {
165172
$print .= ' <fg=black;bg=green>[Changelog not found]</>';
166-
} elseif ($pull['changelog'] && !$requiredChangelog) {
173+
} elseif ($pull['changelog'] && 'stable' === $pull['stability']) {
167174
$print .= ' <fg=black;bg=yellow>[Changelog found]</>';
168175
} else {
169176
$print .= ' <fg=black;bg=green>[Changelog found]</>';
@@ -235,6 +242,20 @@ private function printChangelog($pulls)
235242
return $print;
236243
}
237244

245+
private function generatePullRequestStability($pull)
246+
{
247+
$stability = 'stable';
248+
foreach ($pull['labels'] as $label) {
249+
if ('minor' === $label['name']) {
250+
$stability = 'minor';
251+
break;
252+
} elseif ('patch' === $label['name']) {
253+
$stability = 'patch';
254+
}
255+
}
256+
return $stability;
257+
}
258+
238259
private function findPullRequestsSince($currentRelease, $repositoryName, $branch)
239260
{
240261
$pulls = $this->githubPaginator->fetchAll($this->githubClient->pullRequests(), 'all', array(
@@ -260,6 +281,7 @@ private function findPullRequestsSince($currentRelease, $repositoryName, $branch
260281
$pull['number']
261282
);
262283
$pull['changelog'] = $this->generateChangelog($pull);
284+
$pull['stability'] = $this->generatePullRequestStability($pull);
263285

264286
$filteredPulls[] = $pull;
265287
}

0 commit comments

Comments
 (0)