Skip to content

Commit 73b95f7

Browse files
author
Your Name
committed
updated with suggestions
1 parent 4f907fe commit 73b95f7

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/VCS/Adapter/Git/Gitea.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public function getUser(string $username): array
533533

534534
public function getOwnerName(string $installationId, ?int $repositoryId = null): string
535535
{
536-
if ($repositoryId === null) {
536+
if ($repositoryId === null || $repositoryId <= 0) {
537537
throw new Exception("repositoryId is required for Gitea");
538538
}
539539

@@ -555,11 +555,11 @@ public function getOwnerName(string $installationId, ?int $repositoryId = null):
555555
$responseBody = $response['body'] ?? [];
556556
$owner = $responseBody['owner'] ?? [];
557557

558-
if (!array_key_exists('login', $owner)) {
559-
throw new Exception("Owner login missing in response");
558+
if (empty($owner['login'])) {
559+
throw new Exception("Owner login missing or empty in response");
560560
}
561561

562-
return $owner['login'] ?? '';
562+
return $owner['login'];
563563
}
564564

565565
public function getPullRequest(string $owner, string $repositoryName, int $pullRequestNumber): array

tests/VCS/Adapter/GiteaTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,16 +725,26 @@ public function testGetOwnerName(): void
725725
$repositoryName = 'test-get-owner-name-' . \uniqid();
726726
$created = $this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);
727727

728-
$this->assertIsArray($created);
729-
$this->assertArrayHasKey('id', $created);
730-
$this->assertIsScalar($created['id']);
731-
$repositoryId = (int) $created['id'];
728+
try {
729+
$this->assertIsArray($created);
730+
$this->assertArrayHasKey('id', $created);
731+
$this->assertIsScalar($created['id']);
732+
$repositoryId = (int) $created['id'];
732733

733-
$ownerName = $this->vcsAdapter->getOwnerName('', $repositoryId);
734+
$ownerName = $this->vcsAdapter->getOwnerName('', $repositoryId);
734735

735-
$this->assertSame(self::$owner, $ownerName);
736+
$this->assertSame(self::$owner, $ownerName);
737+
} finally {
738+
$this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
739+
}
740+
}
736741

737-
$this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
742+
public function testGetOwnerNameWithZeroRepositoryId(): void
743+
{
744+
$this->expectException(\Exception::class);
745+
$this->expectExceptionMessage('repositoryId is required for Gitea');
746+
747+
$this->vcsAdapter->getOwnerName('', 0);
738748
}
739749

740750
public function testGetOwnerNameWithoutRepositoryId(): void

0 commit comments

Comments
 (0)