Skip to content

Commit b5d6e19

Browse files
Merge pull request #84 from marcocesarato/copilot/add-commit-author-feature
Add option to include commit author
2 parents 6bcd67d + 3c97460 commit b5d6e19

4 files changed

Lines changed: 65 additions & 1 deletion

File tree

docs/config.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dir or use the `--config` option to specify the location of your configuration f
2929
- **Skip Verify:** Skip the pre-commit and commit-msg hooks
3030
- **Disable Links:** Render text instead of link in changelog
3131
- **Hidden Hash:** Hide commit hash from changelog
32+
- **Hidden Author:** Hide commit author from changelog (default: true)
3233
- **Hidden Mentions:** Hide users mentions from changelog
3334
- **Hidden References:** Hide issue references from changelog
3435
- **Pretty Scope:** Prettify the scope commit part (section name) on changelog *(ex. UserManager => User Manager or
@@ -90,6 +91,7 @@ return [
9091
'skipVerify' => false,
9192
'disableLinks' => false,
9293
'hiddenHash' => false,
94+
'hiddenAuthor' => true,
9395
'hiddenMentions' => false,
9496
'hiddenReferences' => false,
9597
'prettyScope' => true,
@@ -127,6 +129,23 @@ return [
127129
];
128130
```
129131

132+
#### Example with Author Information
133+
134+
To show author information in your changelog:
135+
136+
```php
137+
<?php
138+
139+
return [
140+
// Show author information in changelog entries (default: true = hidden)
141+
'hiddenAuthor' => false,
142+
// Optionally also show other metadata
143+
'hiddenHash' => false, // Show commit hash
144+
'hiddenMentions' => false, // Show @mentions
145+
'hiddenReferences' => false, // Show issue references
146+
];
147+
```
148+
130149
#### Full Example
131150

132151
```php

src/Changelog.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,11 @@ protected function getMarkdownChanges(array $changes): string
569569
$sha = '';
570570
$references = '';
571571
$mentions = '';
572+
$author = '';
572573
$shaGroup = [];
573574
$refsGroup = [];
574575
$mentionsGroup = [];
576+
$authorGroup = [];
575577
foreach ($itemsList as $item) {
576578
$description = ucfirst($item->getDescription());
577579
// Hashes
@@ -600,6 +602,11 @@ protected function getMarkdownChanges(array $changes): string
600602
$mentionsGroup[] = $text;
601603
}
602604
}
605+
// Author
606+
if (!$this->config->isHiddenAuthor() && !empty($item->getAuthorName())) {
607+
$authorName = $item->getAuthorName();
608+
$authorGroup[] = $authorName;
609+
}
603610
}
604611

605612
if (!$this->config->isHiddenHash() && !empty($shaGroup)) {
@@ -611,7 +618,10 @@ protected function getMarkdownChanges(array $changes): string
611618
if (!$this->config->isHiddenMentions() && !empty($mentionsGroup)) {
612619
$mentions = '*[*' . implode(', ', $mentionsGroup) . '*]*';
613620
}
614-
$changelog .= Formatter::clean("* {$description} {$references} {$sha} {$mentions}");
621+
if (!$this->config->isHiddenAuthor() && !empty($authorGroup)) {
622+
$author = '*by ' . implode(', ', array_unique($authorGroup)) . '*';
623+
}
624+
$changelog .= Formatter::clean("* {$description} {$references} {$sha} {$author} {$mentions}");
615625
$changelog .= PHP_EOL;
616626
}
617627
}

src/Configuration.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ class Configuration
166166
*/
167167
protected $hiddenHash = false;
168168

169+
/**
170+
* Hidden author.
171+
*
172+
* @var bool
173+
*/
174+
protected $hiddenAuthor = true;
175+
169176
/**
170177
* Tag suffix.
171178
*
@@ -315,6 +322,7 @@ public function fromArray(array $array)
315322
'skipVerify' => $this->skipVerify(),
316323
'disableLinks' => $this->isDisableLinks(),
317324
'hiddenHash' => $this->isHiddenHash(),
325+
'hiddenAuthor' => $this->isHiddenAuthor(),
318326
'hiddenMentions' => $this->isHiddenMentions(),
319327
'hiddenReferences' => $this->isHiddenReferences(),
320328
'prettyScope' => $this->isPrettyScope(),
@@ -382,6 +390,7 @@ public function fromArray(array $array)
382390
->setDisableLinks($params['disableLinks'])
383391
// Hidden
384392
->setHiddenHash($params['hiddenHash'])
393+
->setHiddenAuthor($params['hiddenAuthor'])
385394
->setHiddenMentions($params['hiddenMentions'])
386395
->setHiddenReferences($params['hiddenReferences'])
387396
->setHiddenVersionSeparator($params['hiddenVersionSeparator'])
@@ -767,6 +776,18 @@ public function setHiddenHash(bool $hiddenHash): self
767776
return $this;
768777
}
769778

779+
public function isHiddenAuthor(): bool
780+
{
781+
return $this->hiddenAuthor;
782+
}
783+
784+
public function setHiddenAuthor(bool $hiddenAuthor): self
785+
{
786+
$this->hiddenAuthor = $hiddenAuthor;
787+
788+
return $this;
789+
}
790+
770791
public function isPrettyScope(): bool
771792
{
772793
return $this->prettyScope;

tests/ChangelogTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ public function testExecMock()
112112
}
113113

114114
/** @test */
115+
public function testHiddenAuthorConfigurationDefault()
116+
{
117+
$config = new Configuration();
118+
// By default, author should be hidden (true)
119+
$this->assertTrue($config->isHiddenAuthor());
120+
}
121+
122+
/** @test */
123+
public function testHiddenAuthorConfiguration()
124+
{
125+
$config = new Configuration(['hiddenAuthor' => false]);
126+
// Author should not be hidden when set to false
127+
$this->assertFalse($config->isHiddenAuthor());
128+
115129
public function testAzureDevOpsHttpsUrlPatternMatching()
116130
{
117131
// Test Azure DevOps HTTPS URL pattern directly

0 commit comments

Comments
 (0)