Skip to content

Commit

Permalink
feat: annotated tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kishieel committed Jan 2, 2022
1 parent 11b4fe5 commit e738b29
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function generate(string $root, InputInterface $input, SymfonyStyle $outp
$autoCommit = $input->getOption('commit'); // Commit once changelog is generated
$autoCommitAll = $input->getOption('commit-all'); // Commit all changes once changelog is generated
$autoTag = !($input->getOption('no-tag') || $this->config->skipTag()); // Tag release once is committed
$annotateTag = $input->getOption('annotate-tag');
$amend = $input->getOption('amend'); // Amend commit
$hooks = !$input->getOption('no-verify'); // Verify git hooks
$hooks = $hooks && $this->config->skipVerify() ? false : true;
Expand Down Expand Up @@ -419,7 +420,7 @@ public function generate(string $root, InputInterface $input, SymfonyStyle $outp
// Create tag
if ($autoTag) {
$tag = $tagPrefix . $newVersion . $tagSuffix;
$result = Repository::tag($tag);
$result = Repository::tag($tag, $annotateTag);
if ($result !== false) {
$output->success("Release tagged with success! New version: {$tag}");
} else {
Expand Down
1 change: 1 addition & 0 deletions src/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protected function configure()
new InputOption('history', null, InputOption::VALUE_NONE, 'Generate the entire history of changes of all releases'),
new InputOption('no-verify', null, InputOption::VALUE_NONE, 'Bypasses the pre-commit and commit-msg hooks'),
new InputOption('no-tag', null, InputOption::VALUE_NONE, 'Disable release auto tagging'),
new InputOption('annotate-tag', null, InputOption::VALUE_OPTIONAL, 'Make an unsigned, annotated tag object once changelog is generated', false),
new InputOption('merged', null, InputOption::VALUE_NONE, 'Only include commits whose tips are reachable from HEAD.'),
]);
}
Expand Down
13 changes: 8 additions & 5 deletions src/Git/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public static function getLastCommit(): string
public static function getLastTag($merged = false, $prefix = ''): string
{
$merged = ($merged) ? '--merged' : '';
return self::run("git for-each-ref 'refs/tags/". $prefix . "*' --sort=-v:refname --format='%(refname:strip=2)' --count=1 {$merged}");

return self::run("git for-each-ref 'refs/tags/" . $prefix . "*' --sort=-v:refname --format='%(refname:strip=2)' --count=1 {$merged}");
}

/**
Expand Down Expand Up @@ -145,7 +145,7 @@ public static function getCommits(string $options = ''): array
*/
public static function getTags($prefix = ''): array
{
$tags = self::run("git tag '". $prefix . "*' --sort=-v:refname --list --format='%(refname:strip=2)" . self::$delimiter . "'") . "\n";
$tags = self::run("git tag '" . $prefix . "*' --sort=-v:refname --list --format='%(refname:strip=2)" . self::$delimiter . "'") . "\n";
$tagsArray = explode(self::$delimiter . "\n", $tags);
array_pop($tagsArray);

Expand Down Expand Up @@ -205,9 +205,12 @@ public static function commit(string $message, array $files = [], bool $amend =
*
* @return string
*/
public static function tag(string $name)
public static function tag(string $name, $annotation = false)
{
return exec("git tag {$name}");
$message = $annotation ?: $name;
$flags = $annotation !== false ? "-a -m {$message}" : '';

return exec("git tag {$flags} {$name}");
}

/**
Expand Down

0 comments on commit e738b29

Please sign in to comment.