Skip to content

Commit

Permalink
fix: semantic version prefix remove
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Oct 27, 2022
1 parent 60274c9 commit a821c13
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,13 @@ public function generate(string $root, InputInterface $input, SymfonyStyle $outp
}

// Generate new version code
$semver = new SemanticVersion($lastVersion);
$semver = new SemanticVersion($lastVersion, $tagPrefix);
$newVersion = $semver->bump($bumpRelease);
}
if (!empty($nextVersion)) {
$newVersion = $nextVersion;
$autoBump = false;
}
$newVersion = preg_replace('#^v#i', '', $newVersion);
$newVersion = preg_replace('/^' . preg_quote($tagPrefix, '/') . '/', '', $newVersion);

$options = []; // Git retrieve options per version
Expand Down Expand Up @@ -344,7 +343,7 @@ public function generate(string $root, InputInterface $input, SymfonyStyle $outp
}

if ($params['autoBump']) {
$semver = new SemanticVersion($params['from']);
$semver = new SemanticVersion($params['from'], $tagPrefix);
$bumpRelease = SemanticVersion::PATCH;

if ($summary['breaking_changes'] > 0) {
Expand Down Expand Up @@ -375,7 +374,7 @@ public function generate(string $root, InputInterface $input, SymfonyStyle $outp
$newVersion = $extraRelease ?? $newVersion;

if ($releaseType !== null) {
$semVer2 = new SemanticVersion($newVersion);
$semVer2 = new SemanticVersion($newVersion, $tagPrefix);
$newVersion = $semVer2->bump($releaseType);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Git/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,15 @@ public static function getLastTag($prefix = '', $merged = false): string

$lastTag = '0.0.0';
foreach ($tagsFound as $value) {
$value = preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $value);
if (SemanticVersion::validate($value)) {
if (SemanticVersion::validate($value, $prefix)) {
$lastTag = $value;
break;
}
}

if (count($tagsFound) > 0) {
foreach ($tagsFound as $found) {
$found = preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $value);
if (SemanticVersion::validate($found)) {
if (SemanticVersion::validate($found, $prefix)) {
$lastTag = $found;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Helper/SemanticVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class SemanticVersion
*
* @param $version
*/
public function __construct($version)
public function __construct($version, $prefix = 'v')
{
$version = trim($version);
$version = preg_replace('#^v#i', '', $version);
$version = preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $version);

$this->setVersion($version);
}
Expand Down Expand Up @@ -137,9 +137,9 @@ public function setVersion(string $version): SemanticVersion
return $this;
}

public static function validate($version): bool
public static function validate($version, $prefix = 'v'): bool
{
$version = preg_replace('#^v#i', '', $version);
$version = preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $version);

return preg_match('/^' . self::PATTERN . '$/', $version);
}
Expand Down

0 comments on commit a821c13

Please sign in to comment.