Skip to content

Commit b51fcfd

Browse files
committed
Add logs when skipping already existing tags
Signed-off-by: Nathanael Esayeas <[email protected]>
1 parent 6c9d81a commit b51fcfd

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

bin/console.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static function (int $errorCode, string $message = '', string $file = '', int $l
128128
$getMilestone,
129129
$commitChangelog,
130130
$createReleaseText,
131-
new CreateTagViaConsole(new HasTagViaConsole()),
131+
new CreateTagViaConsole(new HasTagViaConsole(), $logger),
132132
$push,
133133
$createRelease,
134134
),

src/Git/CreateTagViaConsole.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
use Psl\File;
1111
use Psl\Filesystem;
1212
use Psl\Shell;
13+
use Psr\Log\LoggerInterface;
1314

1415
use function sprintf;
1516

1617
final class CreateTagViaConsole implements CreateTag
1718
{
18-
public function __construct(private HasTag $hasTag)
19-
{
19+
public function __construct(
20+
private readonly HasTag $hasTag,
21+
private readonly LoggerInterface $logger,
22+
) {
2023
}
2124

2225
public function __invoke(
@@ -26,7 +29,11 @@ public function __invoke(
2629
string $changelog,
2730
SecretKeyId $keyId,
2831
): void {
29-
if (($this->hasTag)($repositoryDirectory, $tagName) === true) {
32+
if (($this->hasTag)($repositoryDirectory, $tagName)) {
33+
$this->logger->info(
34+
sprintf('[CreateTagViaConsole] Skipping this step; tag "%s" already exists.', $tagName),
35+
);
36+
3037
return;
3138
}
3239

test/unit/Git/CreateTagViaConsoleTest.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
use Psl\Filesystem;
1616
use Psl\Shell;
1717
use Psr\Http\Message\UriInterface;
18+
use Psr\Log\LoggerInterface;
1819

1920
use function Psl\File\read;
21+
use function sprintf;
2022

2123
/** @covers \Laminas\AutomaticReleases\Git\CreateTagViaConsole */
2224
final class CreateTagViaConsoleTest extends TestCase
@@ -48,6 +50,9 @@ protected function setUp(): void
4850

4951
public function testCreatesSignedTag(): void
5052
{
53+
$logger = $this->createMock(LoggerInterface::class);
54+
$logger->expects(self::never())->method('info');
55+
5156
$sourceUri = $this->createMock(UriInterface::class);
5257
$sourceUri->method('__toString')->willReturn($this->repository);
5358

@@ -56,7 +61,7 @@ public function testCreatesSignedTag(): void
5661
->with($this->repository, 'name-of-the-tag')
5762
->willReturn(false);
5863

59-
(new CreateTagViaConsole($hasTag))(
64+
(new CreateTagViaConsole($hasTag, $logger))(
6065
$this->repository,
6166
BranchName::fromName('tag-branch'),
6267
'name-of-the-tag',
@@ -76,31 +81,41 @@ public function testCreatesSignedTag(): void
7681

7782
public function testSkipsIfTagAlreadyExists(): void
7883
{
84+
$tagName = 'name-of-the-tag';
85+
$logger = $this->createMock(LoggerInterface::class);
86+
$logger->expects(self::never())
87+
->method('info');
88+
7989
$sourceUri = $this->createMock(UriInterface::class);
8090
$sourceUri->method('__toString')->willReturn($this->repository);
8191

8292
$hasTag = new HasTagViaConsole();
8393

84-
(new CreateTagViaConsole($hasTag))(
94+
(new CreateTagViaConsole($hasTag, $logger))(
8595
$this->repository,
8696
BranchName::fromName('tag-branch'),
87-
'name-of-the-tag',
97+
$tagName,
8898
'changelog text for the tag',
8999
$this->key,
90100
);
91101

92-
Shell\execute('git', ['tag', '-v', 'name-of-the-tag'], $this->repository);
93-
$fetchedTag = Shell\execute('git', ['show', 'name-of-the-tag'], $this->repository);
102+
Shell\execute('git', ['tag', '-v', $tagName], $this->repository);
103+
$fetchedTag = Shell\execute('git', ['show', $tagName], $this->repository);
94104

95105
self::assertStringContainsString('tag name-of-the-tag', $fetchedTag);
96106
self::assertStringContainsString('changelog text for the tag', $fetchedTag);
97107
self::assertStringContainsString('a commit', $fetchedTag);
98108
self::assertStringContainsString('-----BEGIN PGP SIGNATURE-----', $fetchedTag);
99109

100-
(new CreateTagViaConsole($hasTag))(
110+
$logger = $this->createMock(LoggerInterface::class);
111+
$logger->expects(self::once())
112+
->method('info')
113+
->with(sprintf('[CreateTagViaConsole] Skipping this step; tag "%s" already exists.', $tagName));
114+
115+
(new CreateTagViaConsole($hasTag, $logger))(
101116
$this->repository,
102117
BranchName::fromName('tag-branch'),
103-
'name-of-the-tag',
118+
$tagName,
104119
'changelog text for the tag',
105120
$this->key,
106121
);

0 commit comments

Comments
 (0)