Skip to content
Merged
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 src/DTO/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct(
public string $url,
public ?string $authorEmail = null,
public bool $hasDependenciesChanges = false,
public ?string $message = null,
) {
}

Expand All @@ -34,6 +35,7 @@ public function withHasDependenciesChanges(bool $hasDependenciesChanges): self
$this->url,
$this->authorEmail,
$hasDependenciesChanges,
$this->message,
);
}
}
5 changes: 4 additions & 1 deletion src/Provider/Github/CommitParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down
1 change: 1 addition & 0 deletions src/Provider/Gitlab/CommitParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
5 changes: 5 additions & 0 deletions tests/Unit/DTO/CommitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -53,6 +55,7 @@ public function testDefaultValues(): void

$this->assertNull($commit->authorEmail);
$this->assertFalse($commit->hasDependenciesChanges);
$this->assertNull($commit->message);
}

public function testWithHasDependenciesChangesReturnsNewInstance(): void
Expand All @@ -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);
Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions tests/Unit/DiffParser/DiffParserRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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);
}
Expand All @@ -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]);

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Provider/Github/CommitParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Provider/Gitlab/CommitParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
Loading