From d0d484e7a3c26d45eaf62be7ef026a06079066aa Mon Sep 17 00:00:00 2001 From: Anthony Delgado Date: Fri, 20 Mar 2026 08:33:51 +0100 Subject: [PATCH 1/2] feat(commit): Add message field --- src/DTO/Commit.php | 2 ++ src/Provider/Github/CommitParser.php | 5 ++++- src/Provider/Gitlab/CommitParser.php | 1 + tests/Unit/DTO/CommitTest.php | 5 +++++ tests/Unit/Provider/Github/CommitParserTest.php | 1 + tests/Unit/Provider/Gitlab/CommitParserTest.php | 2 ++ 6 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/DTO/Commit.php b/src/DTO/Commit.php index 73703ce..10683e5 100644 --- a/src/DTO/Commit.php +++ b/src/DTO/Commit.php @@ -21,6 +21,7 @@ public function __construct( public string $url, public ?string $authorEmail = null, public bool $hasDependenciesChanges = false, + public ?string $message = null, ) { } @@ -34,6 +35,7 @@ public function withHasDependenciesChanges(bool $hasDependenciesChanges): self $this->url, $this->authorEmail, $hasDependenciesChanges, + $this->message, ); } } diff --git a/src/Provider/Github/CommitParser.php b/src/Provider/Github/CommitParser.php index f54992b..73a769f 100644 --- a/src/Provider/Github/CommitParser.php +++ b/src/Provider/Github/CommitParser.php @@ -24,13 +24,16 @@ public function parse(array $data): Commit $commitData = $data['commit'] ?? []; $authorData = $commitData['author'] ?? []; + $message = (string) ($commitData['message'] ?? ''); + return new Commit( id: substr((string) $data['sha'], 0, 8), - title: $this->extractTitle((string) ($commitData['message'] ?? '')), + title: $this->extractTitle($message), date: new \DateTimeImmutable((string) ($authorData['date'] ?? 'now')), author: (string) ($authorData['name'] ?? ''), url: (string) ($data['html_url'] ?? ''), authorEmail: $authorData['email'] ?? null, + message: $message !== '' ? $message : null, ); } diff --git a/src/Provider/Gitlab/CommitParser.php b/src/Provider/Gitlab/CommitParser.php index e22ac6c..a316de0 100644 --- a/src/Provider/Gitlab/CommitParser.php +++ b/src/Provider/Gitlab/CommitParser.php @@ -28,6 +28,7 @@ public function parse(array $data): Commit author: (string) $data['author_name'], url: (string) $data['web_url'], authorEmail: $data['author_email'] ?? null, + message: isset($data['message']) ? (string) $data['message'] : null, ); } } diff --git a/tests/Unit/DTO/CommitTest.php b/tests/Unit/DTO/CommitTest.php index 34720a3..5df99b2 100644 --- a/tests/Unit/DTO/CommitTest.php +++ b/tests/Unit/DTO/CommitTest.php @@ -30,6 +30,7 @@ public function testConstructorSetsAllProperties(): void url: 'https://github.com/org/repo/commit/abc12345', authorEmail: 'john@example.com', hasDependenciesChanges: true, + message: "Fix bug in parser\n\nExtended description.", ); $this->assertSame('abc12345', $commit->id); @@ -39,6 +40,7 @@ public function testConstructorSetsAllProperties(): void $this->assertSame('https://github.com/org/repo/commit/abc12345', $commit->url); $this->assertSame('john@example.com', $commit->authorEmail); $this->assertTrue($commit->hasDependenciesChanges); + $this->assertSame("Fix bug in parser\n\nExtended description.", $commit->message); } public function testDefaultValues(): void @@ -53,6 +55,7 @@ public function testDefaultValues(): void $this->assertNull($commit->authorEmail); $this->assertFalse($commit->hasDependenciesChanges); + $this->assertNull($commit->message); } public function testWithHasDependenciesChangesReturnsNewInstance(): void @@ -66,6 +69,7 @@ public function testWithHasDependenciesChangesReturnsNewInstance(): void url: 'https://example.com', authorEmail: 'jane@example.com', hasDependenciesChanges: false, + message: "Some commit\n\nDetails.", ); $newCommit = $commit->withHasDependenciesChanges(true); @@ -79,5 +83,6 @@ public function testWithHasDependenciesChangesReturnsNewInstance(): void $this->assertSame($commit->author, $newCommit->author); $this->assertSame($commit->url, $newCommit->url); $this->assertSame($commit->authorEmail, $newCommit->authorEmail); + $this->assertSame($commit->message, $newCommit->message); } } diff --git a/tests/Unit/Provider/Github/CommitParserTest.php b/tests/Unit/Provider/Github/CommitParserTest.php index 9845ec6..cc72733 100644 --- a/tests/Unit/Provider/Github/CommitParserTest.php +++ b/tests/Unit/Provider/Github/CommitParserTest.php @@ -48,6 +48,7 @@ public function testParseReturnsCommitWithAllFields(): void $this->assertSame('john@example.com', $commit->authorEmail); $this->assertSame('https://github.com/org/repo/commit/abc123456789', $commit->url); $this->assertSame('2024-01-15', $commit->date->format('Y-m-d')); + $this->assertSame("Fix critical bug in parser\n\nThis is the extended description.", $commit->message); } public function testParseExtractsFirstLineAsTitle(): void diff --git a/tests/Unit/Provider/Gitlab/CommitParserTest.php b/tests/Unit/Provider/Gitlab/CommitParserTest.php index 580883e..bc61156 100644 --- a/tests/Unit/Provider/Gitlab/CommitParserTest.php +++ b/tests/Unit/Provider/Gitlab/CommitParserTest.php @@ -30,6 +30,7 @@ public function testParseReturnsCommitWithAllFields(): void $data = [ 'id' => 'abc123456789', 'title' => 'Fix critical bug in parser', + 'message' => "Fix critical bug in parser\n\nThis is the extended description.", 'created_at' => '2024-01-15T10:30:00Z', 'author_name' => 'John Doe', 'author_email' => 'john@example.com', @@ -44,6 +45,7 @@ public function testParseReturnsCommitWithAllFields(): void $this->assertSame('john@example.com', $commit->authorEmail); $this->assertSame('https://gitlab.com/org/repo/-/commit/abc123456789', $commit->url); $this->assertSame('2024-01-15', $commit->date->format('Y-m-d')); + $this->assertSame("Fix critical bug in parser\n\nThis is the extended description.", $commit->message); } public function testParseTruncatesIdToEightCharacters(): void From 22cd87c5973b631393a2a5b6f67bdeb35165cad0 Mon Sep 17 00:00:00 2001 From: Anthony Delgado Date: Mon, 23 Mar 2026 10:01:38 +0100 Subject: [PATCH 2/2] Fix php-cs job errors --- src/Provider/Github/CommitParser.php | 2 +- tests/Unit/DiffParser/DiffParserRegistryTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Provider/Github/CommitParser.php b/src/Provider/Github/CommitParser.php index 73a769f..026ccb9 100644 --- a/src/Provider/Github/CommitParser.php +++ b/src/Provider/Github/CommitParser.php @@ -33,7 +33,7 @@ public function parse(array $data): Commit author: (string) ($authorData['name'] ?? ''), url: (string) ($data['html_url'] ?? ''), authorEmail: $authorData['email'] ?? null, - message: $message !== '' ? $message : null, + message: '' !== $message ? $message : null, ); } diff --git a/tests/Unit/DiffParser/DiffParserRegistryTest.php b/tests/Unit/DiffParser/DiffParserRegistryTest.php index ad62ee2..739b0be 100644 --- a/tests/Unit/DiffParser/DiffParserRegistryTest.php +++ b/tests/Unit/DiffParser/DiffParserRegistryTest.php @@ -127,13 +127,13 @@ public function testParseAllAggregatesChangesFromMultipleFiles(): void $composerParser = $this->createMock(DiffParserInterface::class); $composerParser->method('supports') - ->willReturnCallback(fn (string $f) => 'composer.json' === $f); + ->willReturnCallback(static fn (string $f) => 'composer.json' === $f); $composerParser->method('parse') ->willReturn([$composerChange]); $packageParser = $this->createMock(DiffParserInterface::class); $packageParser->method('supports') - ->willReturnCallback(fn (string $f) => 'package.json' === $f); + ->willReturnCallback(static fn (string $f) => 'package.json' === $f); $packageParser->method('parse') ->willReturn([$packageChange]); @@ -148,7 +148,7 @@ public function testParseAllAggregatesChangesFromMultipleFiles(): void $this->assertCount(2, $changes); - $names = array_map(fn ($c) => $c->name, $changes); + $names = array_map(static fn ($c) => $c->name, $changes); $this->assertContains('symfony/http-client', $names); $this->assertContains('lodash', $names); } @@ -162,7 +162,7 @@ public function testParseAllIgnoresUnsupportedFiles(): void $composerParser = $this->createMock(DiffParserInterface::class); $composerParser->method('supports') - ->willReturnCallback(fn (string $f) => 'composer.json' === $f); + ->willReturnCallback(static fn (string $f) => 'composer.json' === $f); $composerParser->method('parse') ->willReturn([$composerChange]);