Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
62 changes: 60 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -870,4 +928,4 @@ protected function isRegex(string $pattern)
{
return @preg_match($pattern, null) !== false;
}
}
}