Skip to content

Commit

Permalink
fix: enable merged feature with new extra logics
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Oct 24, 2022
1 parent ce5d806 commit 6a7d709
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function generate(string $root, InputInterface $input, SymfonyStyle $outp
$firstCommit = Repository::getFirstCommit();

if (!$firstRelease) {
$lastVersion = Repository::getLastTag(); // Last version
$lastVersion = Repository::getLastTag($tagPrefix, $merged); // Last version

$bumpRelease = SemanticVersion::PATCH;

Expand Down
23 changes: 21 additions & 2 deletions src/Git/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ConventionalChangelog\Git;

use ConventionalChangelog\Helper\SemanticVersion;
use ConventionalChangelog\Helper\ShellCommand;
use DateTime;

Expand Down Expand Up @@ -54,9 +55,27 @@ public static function getLastCommit(): string
/**
* Get last tag.
*/
public static function getLastTag(): string
public static function getLastTag($prefix = '', $merged = false): string
{
return self::run('git describe --tags --exclude "*-*" --abbrev=0');
$tags = self::run("git for-each-ref --sort=-v:refname --format='%(refname:strip=2)" . self::$delimiter . "' {$merged}");

$tagsArray = explode(self::$delimiter . "\n", $tags);
$prefixQuote = preg_quote($prefix);
$tagsFound = preg_grep('/^' . $prefixQuote . '[^-]*$/', $tagsArray);

$lastTag = $prefix . '0.0.0';
if (count($tagsFound) > 0) {
foreach ($tagsFound as $found) {
$foundStrip = str_replace($prefix, '', $found);
$semver = new SemanticVersion($foundStrip);
if ($semver->getVersionCode() !== '0.0.0') {
$lastTag = $found;
break;
}
}
}

return $lastTag;
}

/**
Expand Down

0 comments on commit 6a7d709

Please sign in to comment.