diff --git a/src/Changelog.php b/src/Changelog.php index 2f15c36..16915e0 100644 --- a/src/Changelog.php +++ b/src/Changelog.php @@ -146,6 +146,7 @@ public function generate(InputInterface $input, SymfonyStyle $output): int 'to' => $toTag, 'date' => Git::getCommitDate($toTag), 'options' => "{$fromTag}..{$toTag}", + 'autoBump' => false, ]; $previousTag = $toTag; } @@ -155,6 +156,7 @@ public function generate(InputInterface $input, SymfonyStyle $output): int 'to' => $newVersion, 'date' => $today->format('Y-m-d'), 'options' => "{$lastVersion}..HEAD", + 'autoBump' => false, ]; } $options = array_reverse($options); @@ -186,6 +188,7 @@ public function generate(InputInterface $input, SymfonyStyle $output): int 'to' => $newVersion, 'date' => $today->format('Y-m-d'), 'options' => $additionalParams, + 'autoBump' => $autoBump, ]; } @@ -254,6 +257,19 @@ public function generate(InputInterface $input, SymfonyStyle $output): int } } + if ($params['autoBump']) { + $bumpRelease = SemanticVersion::PATCH; + + if ($summary['breaking_changes'] > 0) { + $bumpRelease = SemanticVersion::MAJOR; + } elseif ($summary['feat'] > 0) { + $bumpRelease = SemanticVersion::MINOR; + } + + $semver = new SemanticVersion($params['from']); + $params['to'] = $semver->bump($bumpRelease); + } + // Remote url $url = Git::getRemoteUrl(); // Initialize changelogs diff --git a/src/Configuration.php b/src/Configuration.php index d26a517..7b77fcd 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -90,10 +90,10 @@ public function fromArray(array $array) } $defaults = [ - 'headerTitle' => $this->headerTitle, - 'headerDescription' => $this->headerDescription, - 'path' => $this->path, - 'preset' => array_merge($this->breakingPreset, $this->preset), + 'headerTitle' => $this->getHeaderTitle(), + 'headerDescription' => $this->getHeaderDescription(), + 'path' => $this->getPath(), + 'preset' => $this->getPreset(), 'types' => [], 'ignoreTypes' => ['build', 'chore', 'ci', 'docs', 'refactor', 'revert', 'style', 'test'], ]; @@ -253,4 +253,12 @@ public function setIgnorePatterns(array $ignorePatterns): Configuration return $this; } + + /** + * @return string[][] + */ + public function getPreset() : array + { + return array_merge($this->breakingPreset, $this->preset); + } }