Skip to content
Open
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
13 changes: 12 additions & 1 deletion src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,14 @@ public function getInstallationRepository(string $repositoryName): array
public function getRepository(string $owner, string $repositoryName): array
{
$url = "/repos/{$owner}/{$repositoryName}";

$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"]);

$responseHeaders = $response['headers'] ?? [];
$responseHeadersStatusCode = $responseHeaders['status-code'] ?? 0;
if ($responseHeadersStatusCode === 404 || $responseHeadersStatusCode === 422) {
throw new RepositoryNotFound("Repository not found.");
}
Comment thread
Meldiron marked this conversation as resolved.

return $response['body'] ?? [];
}

Expand Down Expand Up @@ -765,6 +770,12 @@ public function getCommit(string $owner, string $repositoryName, string $commitH

$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"]);

$responseHeaders = $response['headers'] ?? [];
$responseHeadersStatusCode = $responseHeaders['status-code'] ?? 0;
if ($responseHeadersStatusCode === 404 || $responseHeadersStatusCode === 422) {
throw new RepositoryNotFound("Commit not found.");
Comment on lines +775 to +776
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid classifying invalid commit refs as repository deletion

GET /repos/{owner}/{repo}/commits/{ref} returns 422 for invalid commit refs even when the repository exists, but this branch throws RepositoryNotFound, which semantically signals a missing repository. Any caller that handles RepositoryNotFound as a repo-level failure (e.g., cleanup/reinstall flows) will now mis-handle bad SHAs as deleted repos; keep RepositoryNotFound for true repo-missing responses (404) and use a non-repo-specific exception for 422.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly valid, we might want another exception, or new one. depending on what other adapters do

}

$responseBody = $response['body'] ?? [];
$responseBodyAuthor = $responseBody['author'] ?? [];
$responseBodyCommit = $responseBody['commit'] ?? [];
Expand Down
Loading
Loading