Skip to content

Commit 654f6d4

Browse files
committed
feat: Commit description Regex Replace post processing feature
1 parent ec3a4b6 commit 654f6d4

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

.changelog

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ return [
1414
'/' . preg_quote($releaseMessagePrefix, '/') . '.*/i',
1515
'/chore\(changelog\)[:].*/i',
1616
],
17+
'postProcessRegex' => '/\[([A-Z]{2,3})\-([0-9]+)\]/',
18+
'postProcessReplace' => '[[$1-$2]](https://bcvevolve.atlassian.net/browse/$1-$2)',
1719
'releaseCommitMessageFormat' => "{$releaseMessagePrefix}{{currentTag}}",
1820
'postRun' => function () use ($releaseMessagePrefix) {
1921
$lastTag = Repository::getLastTag();

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "marcocesarato/php-conventional-changelog",
33
"description": "Generate changelogs and release notes from a project's commit messages and metadata and automate versioning with semver.org and conventionalcommits.org",
4-
"version": "1.10.7",
4+
"version": "1.10.8",
55
"type": "library",
66
"license": "GPL-3.0-or-later",
77
"minimum-stability": "stable",

src/Changelog.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,12 @@ protected function getMarkdownChanges(array $changes): string
527527
if (!$this->config->isHiddenMentions() && !empty($mentionsGroup)) {
528528
$mentions = '*[*' . implode(', ', $mentionsGroup) . '*]*';
529529
}
530-
$changelog .= Formatter::clean("* {$description} {$references} {$sha} {$mentions}");
530+
$itemDescription = Formatter::clean("* {$description} {$references} {$sha} {$mentions}");
531+
if ($this->config->hasPostProcessEnabled()) {
532+
$itemDescription = preg_replace($this->config->getPostProcessRegex(), $this->config->getPostProcessReplace(), $itemDescription);
533+
}
534+
$changelog .= $itemDescription;
535+
531536
$changelog .= PHP_EOL;
532537
}
533538
}

src/Configuration.php

+55-1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,20 @@ class Configuration
259259
*/
260260
protected $postRun;
261261

262+
/**
263+
* A Regex string to be used on the commit text post processing.
264+
*
265+
* @var string
266+
*/
267+
protected $postProcessRegex = '';
268+
269+
/**
270+
* A Regex replace string to be used on the commit text post processing.
271+
*
272+
* @var string
273+
*/
274+
protected $postProcessReplace = '';
275+
262276
/**
263277
* Constructor.
264278
*/
@@ -307,6 +321,8 @@ public function fromArray(array $array)
307321
'releaseCommitMessageFormat' => $this->getReleaseCommitMessageFormat(),
308322
'preRun' => $this->getPreRun(),
309323
'postRun' => $this->getPostRun(),
324+
'postProcessRegex' => $this->getPostProcessRegex(),
325+
'postProcessReplace' => $this->getPostProcessReplace(),
310326
];
311327

312328
$params = array_replace_recursive($defaults, $array);
@@ -372,7 +388,10 @@ public function fromArray(array $array)
372388
->setReleaseCommitMessageFormat($params['releaseCommitMessageFormat'])
373389
// Hooks
374390
->setPreRun($params['preRun'])
375-
->setPostRun($params['postRun']);
391+
->setPostRun($params['postRun'])
392+
// Text PostProcessing
393+
->setPostProcessRegex($params['postProcessRegex'])
394+
->setPostProcessReplace($params['postProcessReplace']);
376395
}
377396

378397
/**
@@ -825,6 +844,41 @@ public function setPostRun($postRun): self
825844
return $this;
826845
}
827846

847+
public function getPostProcessRegex(): string
848+
{
849+
return $this->postProcessRegex;
850+
}
851+
852+
/**
853+
* @param mixed $postProcessRegex
854+
*/
855+
public function setPostProcessRegex($postProcessRegex): self
856+
{
857+
$this->postProcessRegex = $postProcessRegex;
858+
859+
return $this;
860+
}
861+
862+
public function getPostProcessReplace(): string
863+
{
864+
return $this->postProcessReplace;
865+
}
866+
867+
/**
868+
* @param mixed $postProcessReplace
869+
*/
870+
public function setPostProcessReplace($postProcessReplace): self
871+
{
872+
$this->postProcessReplace = $postProcessReplace;
873+
874+
return $this;
875+
}
876+
877+
public function hasPostProcessEnabled(): bool
878+
{
879+
return !empty($this->getPostProcessRegex()) && !empty($this->getPostProcessReplace());
880+
}
881+
828882
public function isPackageBump(): bool
829883
{
830884
return $this->packageBump;

0 commit comments

Comments
 (0)