Skip to content

Commit

Permalink
feat: add to tag and from tag options
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Jan 21, 2021
1 parent 0137fae commit 0b0c4b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ php vendor/bin/conventional-changelog

To generate your changelog with auto commit and auto versioning tagging

> Note: the version code by default, will be added one to the `PATCH` semver part (`MAJOR.MINOR.PATCH+1`) of the latest git tag *(Example, if the last version is `1.0.2` the newer, if not specified the version code, will be `1.0.3`)*.
> **Note:** the version code by default, will be added one to the `PATCH` semver part (`MAJOR.MINOR.PATCH+1`) of the latest git tag *(Example, if the last version is `1.0.2` the newer, if not specified the version code, will be `1.0.3`)*.
> See also `--major`, `--minor`, `--patch`, `--rc`, `--beta`, `--alpha` options.
```shell
Expand Down Expand Up @@ -164,6 +164,8 @@ php vendor/bin/conventional-changelog --ver="2.0.1"
--first-release bool Run at first release (if --ver isn't specified version code will be 1.0.0)
--to-date str Get commits from last tag date (or specified on --from-date) to specified date [YYYY-MM-DD]
--from-date str Get commits from specified date [YYYY-MM-DD]
--to-tag str Get commits from last tag (or specified on --from-tag) to specified tag
--from-tag str Get commits from specified tag
--ver str Specify the next release version code (semver)
--history bool Generate the entire history of changes of all releases
--no-verify bool Bypasses the pre-commit and commit-msg hooks
Expand Down
27 changes: 26 additions & 1 deletion src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function generate(InputInterface $input, SymfonyStyle $output): int
$hooks = !$input->getOption('no-verify'); // Verify git hooks
$fromDate = $input->getOption('from-date');
$toDate = $input->getOption('to-date');
$fromTag = $input->getOption('from-tag');
$toTag = $input->getOption('to-tag');
$history = $input->getOption('history');

$firstRelease = $input->getOption('first-release');
Expand Down Expand Up @@ -165,14 +167,36 @@ public function generate(InputInterface $input, SymfonyStyle $output): int
// Get all commits from the first one
$additionalParams = "{$firstCommit}..HEAD";
$lastVersion = $firstCommit;
if (empty($fromTag)) {
$fromTag = $firstCommit;
}
} else {
// Get latest commits from last version date
$additionalParams = "{$lastVersion}..HEAD";
if (empty($fromTag)) {
$fromTag = $lastVersion;
}
}

// Clean ranges
if ((!empty($fromDate) || !empty($toDate)) &&
empty($fromTag) &&
empty($toTag)) {
$additionalParams = '';
}

// Tag range
if (!empty($fromTag) ||
!empty($toTag)) {
if (empty($toTag)) {
$toTag = 'HEAD';
}
$additionalParams = "{$fromTag}...{$toTag}";
}

// Date range
if (!empty($fromDate) ||
!empty($toDate)) {
$additionalParams = '';
if (!empty($fromDate)) {
$additionalParams .= ' --since="' . date('Y-m-d', strtotime($fromDate)) . '"';
}
Expand All @@ -183,6 +207,7 @@ public function generate(InputInterface $input, SymfonyStyle $output): int
$todayString = Format::getDateString($today);
}
}

$options[$lastVersion] = [
'from' => $lastVersion,
'to' => $newVersion,
Expand Down
14 changes: 7 additions & 7 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ public function setIgnorePatterns(array $ignorePatterns): Configuration
return $this;
}

/**
* @return string[][]
*/
public function getPreset() : array
{
return array_merge($this->breakingPreset, $this->preset);
}
/**
* @return string[][]
*/
public function getPreset(): array
{
return array_merge($this->breakingPreset, $this->preset);
}
}
2 changes: 2 additions & 0 deletions src/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ protected function configure()
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]'),
new InputOption('from-tag', null, InputOption::VALUE_REQUIRED, 'Get commits from specified tag'),
new InputOption('to-tag', null, InputOption::VALUE_REQUIRED, 'Get commits last tag (or specified on --from-tag) to specified tag'),
new InputOption('major', null, InputOption::VALUE_NONE, 'Major release (important changes)'),
new InputOption('minor', null, InputOption::VALUE_NONE, 'Minor release (add functionality)'),
new InputOption('patch', null, InputOption::VALUE_NONE, 'Patch release (bug fixes) [default]'),
Expand Down

0 comments on commit 0b0c4b0

Please sign in to comment.