Skip to content

Commit

Permalink
Adding API endpoints to interact with custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ONyklicek committed Jan 7, 2025
1 parent dcd8ded commit 82fc88a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
20 changes: 11 additions & 9 deletions lib/Github/Api/Repository/CustomProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@
class CustomProperties extends AbstractApi
{
/**
* @param string $owner The account owner of the repository.
* @param string $owner The account owner of the repository.
* @param string $repository The name of the repository.
* @return array|string
*/
public function all(string $owner, string $repository)
{
return $this->get('/repos/' . rawurlencode($owner) . '/' . rawurlencode($repository) . '/properties/values');
return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/properties/values');
}

/**
* @param string $owner The account owner of the repository.
* @param string $repository The name of the repository.
* @param string $owner The account owner of the repository.
* @param string $repository The name of the repository.
* @param string $propertyName The name of the property to retrieve.
* @return array
*
* @throws RuntimeException if the property is not found.
*
* @return array
*/
public function show(string $owner, string $repository, string $propertyName): array
{
$allProperties = $this->all($owner, $repository);

if(!is_array($allProperties)) {
if (!is_array($allProperties)) {
throw new RuntimeException('Unexpected response from GitHub API.');
}

Expand All @@ -47,13 +49,13 @@ public function show(string $owner, string $repository, string $propertyName): a
}

/**
* @param string $owner The account owner of the repository.
* @param string $repository The name of the repository.
* @param string $owner The account owner of the repository.
* @param string $repository The name of the repository.
* @param array<string, mixed> $params
* @return array|string
*/
public function update(string $owner, string $repository, array $params)
{
return $this->patch('/repos/' . rawurlencode($owner) . '/' . rawurlencode($repository) . '/properties/values', $params);
return $this->patch('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/properties/values', $params);
}
}
8 changes: 6 additions & 2 deletions test/Github/Tests/Api/Repository/CustomPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public function testShowPropertyExists()
->with('/repos/owner/repo/properties/values')
->willReturn($allProperties);

$expectedResult = ['property_name' =>'property2', 'value' => 'value2'];
$expectedResult = [
'property_name' => 'property2',
'value' => 'value2'
];

$this->assertEquals($expectedResult, $api->show('owner', 'repo', 'property2'));
}

Expand All @@ -51,7 +55,7 @@ public function testShowPropertyDoesNotExist()
->willReturn($allProperties);

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage("Property [property3] not found.");
$this->expectExceptionMessage('Property [property3] not found.');

$api->show('owner', 'repo', 'property3');
}
Expand Down

0 comments on commit 82fc88a

Please sign in to comment.