Skip to content

Commit

Permalink
Add Option to sort the changelog by tags in ascending/descending order
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiLive committed Oct 22, 2020
1 parent 52de68a commit 5f6473d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/GitChangeLog.php
Expand Up @@ -143,6 +143,7 @@ class GitChangeLog
* noChangesMessage Message to show when there are no commit subjects to list for a tag.
* addHashes True includes commit hashes to the listed subjects.
* includeMergeCommits True includes merge commits in the subject lists.
* tagOrderDesc True to sort the tags in descending order.
* </pre>
*/
protected $options = [
Expand All @@ -152,6 +153,7 @@ class GitChangeLog
'noChangesMessage' => 'No changes.',
'addHashes' => true,
'includeMergeCommits' => false,
'tagOrderDesc' => true,
];

/**
Expand Down Expand Up @@ -233,16 +235,21 @@ public function build(): void
{
$logContent = $this->options['logHeader'];
$hashesString = '';
$commitData = $this->fetchCommitData();

if (empty($this->fetchCommitData())) {
if (empty($commitData)) {
$logContent .= $this->options['noChangesMessage'];
$this->changelog = $logContent . "\n";

return;
}

if (!$this->options['tagOrderDesc']) {
$commitData = array_reverse($commitData);
}

// Build changelog.
foreach ($this->fetchCommitData() as $tag => &$data) {
foreach ($commitData as $tag => &$data) {
// Add tag header and date.
if ($tag == 'HEAD') {
$tag = $this->options['headSubject'];
Expand Down

0 comments on commit 5f6473d

Please sign in to comment.