Skip to content

Commit

Permalink
feat: add amend and no verify options
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Jan 18, 2021
1 parent 9cbf69c commit 625ed1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function generate(InputInterface $input, SymfonyStyle $output)
$root = $input->getArgument('path'); // Root

$autoCommit = $input->getOption('commit'); // Commit once changelog is generated
$amend = $input->getOption('amend'); // Amend commit
$hooks = !$input->getOption('no-verify'); // Verify git hooks
$fromDate = $input->getOption('from-date');
$toDate = $input->getOption('to-date');
$history = $input->getOption('history');
Expand All @@ -52,6 +54,11 @@ public function generate(InputInterface $input, SymfonyStyle $output)
unset($this->config->types['refactor']);
}

// If have amend option enable commit
if ($amend) {
$autoCommit = true;
}

// Initialize changelogs
$file = $root . DIRECTORY_SEPARATOR . $this->config->getFileName();
$changelogCurrent = '';
Expand Down Expand Up @@ -243,7 +250,7 @@ public function generate(InputInterface $input, SymfonyStyle $output)

// Create commit and add tag
if ($autoCommit) {
Git::commit("chore(release): {$newVersion}", [$file]);
Git::commit("chore(release): {$newVersion}", [$file], $amend, $hooks);
Git::tag('v' . $newVersion);

$output->success("Committed new version with tag: v{$newVersion}");
Expand Down
2 changes: 2 additions & 0 deletions src/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected function configure()
->setDefinition([
new InputArgument('path', InputArgument::OPTIONAL, 'Define the path directory where generate changelog', getcwd()),
new InputOption('commit', 'c', InputOption::VALUE_NONE, 'Commit the new release once changelog is generated'),
new InputOption('amend', null, InputOption::VALUE_NONE, 'Amend commit the new release once changelog is generated'),
new InputOption('first-release', null, InputOption::VALUE_NONE, 'Run at first release (if --ver isn\'t specified version code it will be 1.0.0)'),
new InputOption('from-date', null, InputOption::VALUE_REQUIRED, 'Get commits from specified date [YYYY-MM-DD]'),
new InputOption('to-date', null, InputOption::VALUE_REQUIRED, 'Get commits last tag date (or specified on --from-date) to specified date [YYYY-MM-DD]'),
Expand All @@ -59,6 +60,7 @@ protected function configure()
new InputOption('history', null, InputOption::VALUE_NONE, 'Generate the entire history of changes of all releases'),
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'),
]);
}

Expand Down
11 changes: 9 additions & 2 deletions src/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,20 @@ public static function getTags()
* @param $message
* @param $files
*/
public static function commit($message, $files = [])
public static function commit($message, $files = [], $amend = false, $verify = true)
{
foreach ($files as $file) {
system("git add \"{$file}\"");
}
$message = str_replace('"', "'", $message); // Escape
system("git commit -m \"{$message}\"");
$command = "git commit -m \"{$message}\"";
if ($amend) {
$command .= ' --amend';
}
if (!$verify) {
$command .= ' --no-verify';
}
system($command);
}

/**
Expand Down

0 comments on commit 625ed1b

Please sign in to comment.