Skip to content

Commit

Permalink
feat: allows own package bumpers
Browse files Browse the repository at this point in the history
  • Loading branch information
attiks authored and marcocesarato committed Oct 27, 2021
1 parent 917103d commit e4aef90
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 164 deletions.
330 changes: 166 additions & 164 deletions docs/config.md
Original file line number Diff line number Diff line change
@@ -1,164 +1,166 @@
# Configuration

For customize settings you just needs to create a file named `.changelog` on the root of your project/ on the working
dir or use the `--config` option to specify the location of your configuration file.

> **Notes:**<br>
> - When a setting on the configuration file is not necessary just omit it
> - To allow all types just keep empty `types` and set empty `ignoreTypes`
## Settings

- **Root:** Working directory of your project
- **Path:** Path to your changelog file (relative to the working dir/root)
- **Header Title:** Header title of the changelog
- **Header Description:** Header subtitle of the changelog
- **Sort By**: Sort changes by commit metadata (date, subject, authorName, authorEmail, authorDate, committerName,
committerEmail, committerDate)
- **Preset:** Add new types preset or modify existing types preset labels and description
- **Types:** Types allowed and showed on changelog. This setting could overwrite ignored types.
- **Package Bump:** Bump the package version in `composer.json` or `package.json` if files exists on the root path
- **Package Lock Commit:** Commit the package lock file (ex. `composer.lock`, `package.lock`, `yarn.lock`...)
- **Ignore Types:** Types ignored and so hidden on changelog
- **Ignore Patterns:** Patterns ignored and so hidden on changelog with a specific description. *(Regex are enabled)*
- **Tag Prefix:** Add prefix to release tag
- **Tag Suffix:** Add suffix to release tag
- **Skip Bump:** Skip automatic version code bump
- **Skip Tag:** Skip automatic commit tagging
- **Skip Verify:** Skip the pre-commit and commit-msg hooks
- **Disable Links:** Render text instead of link in changelog
- **Hidden Hash:** Hide commit hash from changelog
- **Hidden Mentions:** Hide users mentions from changelog
- **Hidden References:** Hide issue references from changelog
- **Pretty Scope:** Prettify the scope commit part (section name) on changelog *(ex. UserManager => User Manager or
user_config => User config)*
- **Url Protocol:** The URL protocol of all repository urls on changelogs (http/https)
- **Date Format:** The [format](https://www.php.net/manual/en/datetime.format.php) of the outputted date string
- **Changelog Version Format:** Allows the version header in changelog to have a configurable format
- **Commit Url Format:** A URL representing a specific commit at a hash
- **Compare Url Format:** A URL representing the comparison between two git sha
- **Issue Url Format:** A URL representing the issue format (allowing a different URL format to be swapped in for
Gitlab, Bitbucket, etc)
- **User Url Format:** A URL representing the a user's profile URL on GitHub, Gitlab, etc. This URL is used for
substituting @abc with https://github.com/abc in commit messages
- **Hidden Version Separator:** Hide version separator
- **Release Commit Message Format:** A string to be used to format the auto-generated release commit message
- **Pre Run**: Run a callback or command before run the script
- **Post Run**: Run a callback or command after run the script

### Default settings

These are the default settings:

```php
<?php

return [
'root' => getcwd(),
'path' => 'CHANGELOG.md',
'headerTitle' => 'Changelog',
'headerDescription' => 'All notable changes to this project will be documented in this file.',
'sortBy' => 'subject',
'preset' => [
// Breaking changes section
'breaking_changes' => ['label' => '⚠ BREAKING CHANGES', 'description' => 'Code changes that potentially causes other components to fail'],
// Types section
'feat' => ['label' => 'Features', 'description' => 'New features'],
'perf' => ['label' => 'Performance Improvements', 'description' => 'Code changes that improves performance'],
'fix' => ['label' => 'Bug Fixes', 'description' => 'Bugs and issues resolution'],
'refactor' => ['label' => 'Code Refactoring', 'description' => 'A code change that neither fixes a bug nor adds a feature'],
'style' => ['label' => 'Styles', 'description' => 'Changes that do not affect the meaning of the code'],
'test' => ['label' => 'Tests', 'description' => 'Adding missing tests or correcting existing tests'],
'build' => ['label' => 'Builds', 'description' => 'Changes that affect the build system or external dependencies '],
'ci' => ['label' => 'Continuous Integrations', 'description' => 'Changes to CI configuration files and scripts'],
'docs' => ['label' => 'Documentation', 'description' => 'Documentation changes'],
'chore' => ['label' => 'Chores', 'description' => "Other changes that don't modify the source code or test files"],
'revert' => ['label' => 'Reverts', 'description' => 'Reverts a previous commit'],
],
'types' => [],
'packageBump' => true,
'packageLockCommit' => true,
'ignoreTypes' => ['build', 'chore', 'ci', 'docs', 'perf', 'refactor', 'revert', 'style', 'test'],
'ignorePatterns' => ['/^chore\(release\):/i'],
'tagPrefix' => 'v',
'tagSuffix' => '',
'skipBump' => false,
'skipTag' => false,
'skipVerify' => false,
'disableLinks' => false,
'hiddenHash' => false,
'hiddenMentions' => false,
'hiddenReferences' => false,
'prettyScope' => true,
'urlProtocol' => 'https',
'dateFormat' => 'Y-m-d',
'changelogVersionFormat' => '## {{version}} ({{date}})',
'commitUrlFormat' => '{{host}}/{{owner}}/{{repository}}/commit/{{hash}}',
'compareUrlFormat' => '{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}',
'issueUrlFormat' => '{{host}}/{{owner}}/{{repository}}/issues/{{id}}',
'userUrlFormat' => '{{host}}/{{user}}',
'releaseCommitMessageFormat' => 'chore(release): {{currentTag}}',
'hiddenVersionSeparator' => false,
'preRun' => null,
'postRun' => null,
];
```

## Examples

Configure your preferences with the help of the following examples.

#### Short Example

```php
<?php

return [
// Types allowed on changelog
'types' => ['feat', 'fix', 'perf', 'docs', 'chore'],
// Ignore chores with changelogs scope
'ignorePatterns' => [
'/chore\(changelog\)[:].*/i'
],
];
```

#### Full Example

```php
<?php

return [
'root' => dirname(__DIR__), // (ex. configs/changelog.php using --config option)
// File changelog (relative to the working dir/root)
'path' => 'docs/CHANGELOG.md', // You can specify a different folder
'headerTitle' => 'My changelog',
'headerDescription' => 'This is my changelog file.',
'preset' => [
// Add improvements type (deprecated type)
'improvements' => [
'label' => 'Improvements',
'description' => 'Improvements to existing features'
],
'chore' => [
// Change chore default label
'label' => 'Others'
],
],
// Types allowed on changelog
'types' => ['feat', 'fix', 'pref'], // These could overwrite ignored types
// Exclude not notables types (following types are the default excluded types)
'ignoreTypes' => ['build', 'chore', 'ci', 'docs', 'refactor', 'revert', 'style', 'test'],
'ignorePatterns' => [
// Exclude all commits with this specific description
'chore(deps): update dependencies',
// You can also use regex to exclude all commit like 'chore(changelog): updated'
'/chore\(changelog\)[:].*/i'
],
'tagPrefix' => 'ver',
'tagSuffix' => '',
'skipBump' => false,
'skipTag' => false,
'skipVerify' => true,
];
```
# Configuration

For customize settings you just needs to create a file named `.changelog` on the root of your project/ on the working
dir or use the `--config` option to specify the location of your configuration file.

> **Notes:**<br>
> - When a setting on the configuration file is not necessary just omit it
> - To allow all types just keep empty `types` and set empty `ignoreTypes`
## Settings

- **Root:** Working directory of your project
- **Path:** Path to your changelog file (relative to the working dir/root)
- **Header Title:** Header title of the changelog
- **Header Description:** Header subtitle of the changelog
- **Sort By**: Sort changes by commit metadata (date, subject, authorName, authorEmail, authorDate, committerName,
committerEmail, committerDate)
- **Preset:** Add new types preset or modify existing types preset labels and description
- **Types:** Types allowed and showed on changelog. This setting could overwrite ignored types.
- **Package Bump:** Bump the package version in `composer.json` or `package.json` if files exists on the root path
- **Package Lock Commit:** Commit the package lock file (ex. `composer.lock`, `package.lock`, `yarn.lock`...)
- **Ignore Types:** Types ignored and so hidden on changelog
- **Ignore Patterns:** Patterns ignored and so hidden on changelog with a specific description. *(Regex are enabled)*
- **Tag Prefix:** Add prefix to release tag
- **Tag Suffix:** Add suffix to release tag
- **Skip Bump:** Skip automatic version code bump
- **Package Bumps:** Array of files to replace version, defaults to `['ConventionalChangelog\PackageBump\ComposerJson', 'ConventionalChangelog\PackageBump\PackageJson']`
- **Skip Tag:** Skip automatic commit tagging
- **Skip Verify:** Skip the pre-commit and commit-msg hooks
- **Disable Links:** Render text instead of link in changelog
- **Hidden Hash:** Hide commit hash from changelog
- **Hidden Mentions:** Hide users mentions from changelog
- **Hidden References:** Hide issue references from changelog
- **Pretty Scope:** Prettify the scope commit part (section name) on changelog *(ex. UserManager => User Manager or
user_config => User config)*
- **Url Protocol:** The URL protocol of all repository urls on changelogs (http/https)
- **Date Format:** The [format](https://www.php.net/manual/en/datetime.format.php) of the outputted date string
- **Changelog Version Format:** Allows the version header in changelog to have a configurable format
- **Commit Url Format:** A URL representing a specific commit at a hash
- **Compare Url Format:** A URL representing the comparison between two git sha
- **Issue Url Format:** A URL representing the issue format (allowing a different URL format to be swapped in for
Gitlab, Bitbucket, etc)
- **User Url Format:** A URL representing the a user's profile URL on GitHub, Gitlab, etc. This URL is used for
substituting @abc with https://github.com/abc in commit messages
- **Hidden Version Separator:** Hide version separator
- **Release Commit Message Format:** A string to be used to format the auto-generated release commit message
- **Pre Run**: Run a callback or command before run the script
- **Post Run**: Run a callback or command after run the script

### Default settings

These are the default settings:

```php
<?php

return [
'root' => getcwd(),
'path' => 'CHANGELOG.md',
'headerTitle' => 'Changelog',
'headerDescription' => 'All notable changes to this project will be documented in this file.',
'sortBy' => 'subject',
'preset' => [
// Breaking changes section
'breaking_changes' => ['label' => '⚠ BREAKING CHANGES', 'description' => 'Code changes that potentially causes other components to fail'],
// Types section
'feat' => ['label' => 'Features', 'description' => 'New features'],
'perf' => ['label' => 'Performance Improvements', 'description' => 'Code changes that improves performance'],
'fix' => ['label' => 'Bug Fixes', 'description' => 'Bugs and issues resolution'],
'refactor' => ['label' => 'Code Refactoring', 'description' => 'A code change that neither fixes a bug nor adds a feature'],
'style' => ['label' => 'Styles', 'description' => 'Changes that do not affect the meaning of the code'],
'test' => ['label' => 'Tests', 'description' => 'Adding missing tests or correcting existing tests'],
'build' => ['label' => 'Builds', 'description' => 'Changes that affect the build system or external dependencies '],
'ci' => ['label' => 'Continuous Integrations', 'description' => 'Changes to CI configuration files and scripts'],
'docs' => ['label' => 'Documentation', 'description' => 'Documentation changes'],
'chore' => ['label' => 'Chores', 'description' => "Other changes that don't modify the source code or test files"],
'revert' => ['label' => 'Reverts', 'description' => 'Reverts a previous commit'],
],
'types' => [],
'packageBump' => true,
'packageBumps' => [],
'packageLockCommit' => true,
'ignoreTypes' => ['build', 'chore', 'ci', 'docs', 'perf', 'refactor', 'revert', 'style', 'test'],
'ignorePatterns' => ['/^chore\(release\):/i'],
'tagPrefix' => 'v',
'tagSuffix' => '',
'skipBump' => false,
'skipTag' => false,
'skipVerify' => false,
'disableLinks' => false,
'hiddenHash' => false,
'hiddenMentions' => false,
'hiddenReferences' => false,
'prettyScope' => true,
'urlProtocol' => 'https',
'dateFormat' => 'Y-m-d',
'changelogVersionFormat' => '## {{version}} ({{date}})',
'commitUrlFormat' => '{{host}}/{{owner}}/{{repository}}/commit/{{hash}}',
'compareUrlFormat' => '{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}',
'issueUrlFormat' => '{{host}}/{{owner}}/{{repository}}/issues/{{id}}',
'userUrlFormat' => '{{host}}/{{user}}',
'releaseCommitMessageFormat' => 'chore(release): {{currentTag}}',
'hiddenVersionSeparator' => false,
'preRun' => null,
'postRun' => null,
];
```

## Examples

Configure your preferences with the help of the following examples.

#### Short Example

```php
<?php

return [
// Types allowed on changelog
'types' => ['feat', 'fix', 'perf', 'docs', 'chore'],
// Ignore chores with changelogs scope
'ignorePatterns' => [
'/chore\(changelog\)[:].*/i'
],
];
```

#### Full Example

```php
<?php

return [
'root' => dirname(__DIR__), // (ex. configs/changelog.php using --config option)
// File changelog (relative to the working dir/root)
'path' => 'docs/CHANGELOG.md', // You can specify a different folder
'headerTitle' => 'My changelog',
'headerDescription' => 'This is my changelog file.',
'preset' => [
// Add improvements type (deprecated type)
'improvements' => [
'label' => 'Improvements',
'description' => 'Improvements to existing features'
],
'chore' => [
// Change chore default label
'label' => 'Others'
],
],
// Types allowed on changelog
'types' => ['feat', 'fix', 'pref'], // These could overwrite ignored types
// Exclude not notables types (following types are the default excluded types)
'ignoreTypes' => ['build', 'chore', 'ci', 'docs', 'refactor', 'revert', 'style', 'test'],
'ignorePatterns' => [
// Exclude all commits with this specific description
'chore(deps): update dependencies',
// You can also use regex to exclude all commit like 'chore(changelog): updated'
'/chore\(changelog\)[:].*/i'
],
'tagPrefix' => 'ver',
'tagSuffix' => '',
'skipBump' => false,
'skipTag' => false,
'skipVerify' => true,
];
```
5 changes: 5 additions & 0 deletions src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public function generate(string $root, InputInterface $input, SymfonyStyle $outp
PackageJson::class,
];

// Allow config to specify own packages.
if ($this->config->getPackageBumps()) {
$packageBumps = $this->config->getPackageBumps();
}

$this->hasValidRemoteUrl = Repository::hasRemoteUrl() && !empty(Repository::parseRemoteUrl());

// Hook pre run
Expand Down
21 changes: 21 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class Configuration
*/
protected $packageBump = true;

/**
* Bump packages.
*
* @var array
*/
protected $packageBumps = [];

/**
* Commit package lock file.
*
Expand Down Expand Up @@ -299,6 +306,7 @@ public function fromArray(array $array)
'preset' => $this->getPreset(),
'types' => [],
'packageBump' => $this->isPackageBump(),
'packageBumps' => [],
'packageLockCommit' => $this->isPackageLockCommit(),
'ignoreTypes' => $this->getIgnoreTypes(),
'ignorePatterns' => $this->getIgnorePatterns(),
Expand Down Expand Up @@ -359,6 +367,7 @@ public function fromArray(array $array)
->setTypes($params['preset'])
// Package
->setPackageBump($params['packageBump'])
->setPackageBumps($params['packageBumps'])
->setPackageLockCommit($params['packageLockCommit'])
// Document
->setHeaderTitle($params['headerTitle'])
Expand Down Expand Up @@ -868,6 +877,18 @@ public function setPackageBump(bool $packageBump): Configuration
return $this;
}

public function setPackageBumps(array $packageBumps): Configuration
{
$this->packageBumps = $packageBumps;

return $this;
}

public function getPackageBumps(): array
{
return $this->packageBumps;
}

public function isPackageLockCommit(): bool
{
return $this->packageLockCommit;
Expand Down

0 comments on commit e4aef90

Please sign in to comment.