Skip to content

Commit

Permalink
feat: add not tag option and add errors on commit and tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Jan 18, 2021
1 parent 625ed1b commit 285ad0a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
27 changes: 22 additions & 5 deletions src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function generate(InputInterface $input, SymfonyStyle $output)
$root = $input->getArgument('path'); // Root

$autoCommit = $input->getOption('commit'); // Commit once changelog is generated
$autoTag = !$input->getOption('no-tag'); // Tag release once is committed
$amend = $input->getOption('amend'); // Amend commit
$hooks = !$input->getOption('no-verify'); // Verify git hooks
$fromDate = $input->getOption('from-date');
Expand Down Expand Up @@ -246,14 +247,30 @@ public function generate(InputInterface $input, SymfonyStyle $output)

// Save new changelog prepending the current one
file_put_contents($file, $mainHeader . "{$changelogNew}{$changelogCurrent}");
$output->success("Changelog generated to: {$file}");
$output->success('Changelog generated!');
$output->writeln(" > Changelog file: {$file}");

// Create commit and add tag
// Create commit
if ($autoCommit) {
Git::commit("chore(release): {$newVersion}", [$file], $amend, $hooks);
Git::tag('v' . $newVersion);
$result = Git::commit("chore(release): {$newVersion}", [$file], $amend, $hooks);
if ($result !== false) {
$output->success('Release committed!');
// Create tag
if ($autoTag) {
$result = Git::tag('v' . $newVersion);
if ($result !== false) {
$output->success("Release tagged with success! New version: v{$newVersion}");
} else {
$output->error('An error occurred tagging the release!');

return Command::FAILURE;
}
}
} else {
$output->error('An error occurred committing the release!');

$output->success("Committed new version with tag: v{$newVersion}");
return Command::FAILURE;
}
}

return Command::SUCCESS;
Expand Down
1 change: 1 addition & 0 deletions src/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected function configure()
new InputOption('no-chores', null, InputOption::VALUE_NONE, 'Exclude chores type from changelog'),
new InputOption('no-refactor', null, InputOption::VALUE_NONE, 'Exclude refactor type from changelog'),
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'),
]);
}

Expand Down
13 changes: 10 additions & 3 deletions src/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public static function getTags()
* Commit.
*
* @param $message
* @param $files
* @param array $files
* @param false $amend
* @param bool $verify
*
* @return string
*/
public static function commit($message, $files = [], $amend = false, $verify = true)
{
Expand All @@ -128,16 +132,19 @@ public static function commit($message, $files = [], $amend = false, $verify = t
if (!$verify) {
$command .= ' --no-verify';
}
system($command);

return exec($command);
}

/**
* Tag.
*
* @param $name
*
* @return string
*/
public static function tag($name)
{
system("git tag {$name}");
return exec("git tag {$name}");
}
}

0 comments on commit 285ad0a

Please sign in to comment.