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
23 changes: 20 additions & 3 deletions src/Infrastructure/GitHub/GitHubReleaseDraftRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,18 +290,35 @@ private function request(string $method, string $path, ?array $json = null): arr
$path,
$json === null ? [] : ['json' => $json],
);
$this->assertSuccess($response->getStatusCode(), $method . ' ' . $path);
$this->assertSuccess(
$response->getStatusCode(),
$method . ' ' . $path,
$response->getContent(false),
);
$data = $response->toArray(false);
if (array_is_list($data)) {
throw new DomainException('GitHub returned an unexpected list response.');
}
return $data;
}

private function assertSuccess(int $status, string $operation): void
private function assertSuccess(int $status, string $operation, ?string $responseBody = null): void
{
if ($status < 200 || $status >= 300) {
throw new DomainException(sprintf('GitHub API failed to %s (%d).', $operation, $status));
$message = null;
if (is_string($responseBody) && $responseBody !== '') {
$decoded = json_decode($responseBody, true);
if (is_array($decoded) && is_string($decoded['message'] ?? null) && $decoded['message'] !== '') {
$message = $decoded['message'];
}
}

throw new DomainException(sprintf(
'GitHub API failed to %s (%d)%s.',
$operation,
$status,
$message === null ? '' : ': ' . $message,
));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ function (string $method, string $url, array $options) use (&$captured): MockRes
self::assertSame(str_repeat('a', 40), $captured['target_commitish']);
}


public function testCreateDraftSurfacesGitHubErrorMessage(): void
{
$client = new MockHttpClient([
$this->json(['message' => 'Resource not accessible by integration'], 403),
], 'https://api.github.test');

$repo = new GitHubReleaseDraftRepository('token', $client, 'https://api.github.test');

$this->expectException(\DomainException::class);
$this->expectExceptionMessage(
'GitHub API failed to POST /repos/LibreSign/libresign/releases (403): Resource not accessible by integration.',
);

$repo->createDraft(
'LibreSign/libresign',
'v15.0.5',
str_repeat('a', 40),
'15.0.5',
'Release body',
false,
);
}

public function testReadsMergerAndPermission(): void
{
$client = new MockHttpClient([
Expand Down
Loading