diff --git a/.changelog b/.changelog index f46356d..2133a24 100644 --- a/.changelog +++ b/.changelog @@ -14,6 +14,8 @@ return [ '/' . preg_quote($releaseMessagePrefix, '/') . '.*/i', '/chore\(changelog\)[:].*/i', ], + 'postProcessRegex' => '/\[([A-Z]{2,3})\-([0-9]+)\]/', + 'postProcessReplace' => '[[$1-$2]](https://some.jira-host.url/browse/$1-$2)', 'releaseCommitMessageFormat' => "{$releaseMessagePrefix}{{currentTag}}", 'postRun' => function () use ($releaseMessagePrefix) { $lastTag = Repository::getLastTag(); diff --git a/composer.json b/composer.json index 66732e8..e174b18 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "marcocesarato/php-conventional-changelog", "description": "Generate changelogs and release notes from a project's commit messages and metadata and automate versioning with semver.org and conventionalcommits.org", - "version": "1.10.7", + "version": "1.10.8", "type": "library", "license": "GPL-3.0-or-later", "minimum-stability": "stable", diff --git a/src/Changelog.php b/src/Changelog.php index 2e5aa4e..156ccc5 100644 --- a/src/Changelog.php +++ b/src/Changelog.php @@ -527,7 +527,12 @@ protected function getMarkdownChanges(array $changes): string if (!$this->config->isHiddenMentions() && !empty($mentionsGroup)) { $mentions = '*[*' . implode(', ', $mentionsGroup) . '*]*'; } - $changelog .= Formatter::clean("* {$description} {$references} {$sha} {$mentions}"); + $itemDescription = Formatter::clean("* {$description} {$references} {$sha} {$mentions}"); + if ($this->config->hasPostProcessEnabled()) { + $itemDescription = preg_replace($this->config->getPostProcessRegex(), $this->config->getPostProcessReplace(), $itemDescription); + } + $changelog .= $itemDescription; + $changelog .= PHP_EOL; } } diff --git a/src/Configuration.php b/src/Configuration.php index ec32ab7..0c70b69 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -259,6 +259,24 @@ class Configuration */ protected $postRun; + /** + * A Regex string to be used on the commit text post processing. + * + * i.e. Jira task link regex [projectLeters-taskNumbers]: '/\[([A-Z]{2,3})\-([0-9]+)\]/' + * + * @var string + */ + protected $postProcessRegex = ''; + + /** + * A Regex replace string to be used on the commit text post processing. + * + * i.e. Jira task link replacement markdown: '[[$1-$2]](https://some.jira-host.url/browse/$1-$2)' + * + * @var string + */ + protected $postProcessReplace = ''; + /** * Constructor. */ @@ -307,6 +325,8 @@ public function fromArray(array $array) 'releaseCommitMessageFormat' => $this->getReleaseCommitMessageFormat(), 'preRun' => $this->getPreRun(), 'postRun' => $this->getPostRun(), + 'postProcessRegex' => $this->getPostProcessRegex(), + 'postProcessReplace' => $this->getPostProcessReplace(), ]; $params = array_replace_recursive($defaults, $array); @@ -372,7 +392,10 @@ public function fromArray(array $array) ->setReleaseCommitMessageFormat($params['releaseCommitMessageFormat']) // Hooks ->setPreRun($params['preRun']) - ->setPostRun($params['postRun']); + ->setPostRun($params['postRun']) + // Text PostProcessing + ->setPostProcessRegex($params['postProcessRegex']) + ->setPostProcessReplace($params['postProcessReplace']); } /** @@ -825,6 +848,41 @@ public function setPostRun($postRun): self return $this; } + public function getPostProcessRegex(): string + { + return $this->postProcessRegex; + } + + /** + * @param mixed $postProcessRegex + */ + public function setPostProcessRegex($postProcessRegex): self + { + $this->postProcessRegex = $postProcessRegex; + + return $this; + } + + public function getPostProcessReplace(): string + { + return $this->postProcessReplace; + } + + /** + * @param mixed $postProcessReplace + */ + public function setPostProcessReplace($postProcessReplace): self + { + $this->postProcessReplace = $postProcessReplace; + + return $this; + } + + public function hasPostProcessEnabled(): bool + { + return !empty($this->getPostProcessRegex()) && !empty($this->getPostProcessReplace()); + } + public function isPackageBump(): bool { return $this->packageBump; @@ -870,4 +928,4 @@ protected function isRegex(string $pattern) { return @preg_match($pattern, null) !== false; } -} +} \ No newline at end of file