Skip to content

Commit dcd8ded

Browse files
committed
Adding API endpoints to interact with custom properties
1 parent 5d678fd commit dcd8ded

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

doc/repo/custom_properties.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Repo / Custom Properties API
2+
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)
3+
4+
For extended info see the [GitHub documentation](https://docs.github.com/en/rest/reference/repos#custom-properties-for-a-repository)
5+
6+
### List custom properties for a repository
7+
8+
```php
9+
$properties = $client->api('repo')->properties()->all('twbs', 'bootstrap');
10+
```
11+
12+
### Get a custom property for a repository
13+
14+
```php
15+
$property = $client->api('repo')->properties()->show('twbs', 'bootstrap', $propertyName);
16+
```
17+
18+
19+
### Update a custom property for a repository
20+
21+
```php
22+
$parameters = [
23+
'property_name' => 'foo',
24+
'value' => 'bar'
25+
]
26+
27+
$property = $client->api('repo')->properties()->update('twbs', 'bootstrap', $params);
28+
```

lib/Github/Api/Repository/CustomProperties.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function all(string $owner, string $repository)
2929
* @return array
3030
* @throws RuntimeException if the property is not found.
3131
*/
32-
public function show(string $owner, string $repository, string $propertyName)
32+
public function show(string $owner, string $repository, string $propertyName): array
3333
{
3434
$allProperties = $this->all($owner, $repository);
3535

@@ -43,18 +43,17 @@ public function show(string $owner, string $repository, string $propertyName)
4343
}
4444
}
4545

46-
throw new RuntimeException("Property '{$propertyName}' not found.");
46+
throw new RuntimeException("Property [$propertyName] not found.");
4747
}
4848

4949
/**
5050
* @param string $owner The account owner of the repository.
5151
* @param string $repository The name of the repository.
52-
* @param array<string, string|int> $params
52+
* @param array<string, mixed> $params
5353
* @return array|string
5454
*/
55-
public function createOrUpdate(string $owner, string $repository, array $params)
55+
public function update(string $owner, string $repository, array $params)
5656
{
5757
return $this->patch('/repos/' . rawurlencode($owner) . '/' . rawurlencode($repository) . '/properties/values', $params);
5858
}
59-
6059
}

test/Github/Tests/Api/Repository/CustomPropertiesTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testShowPropertyExists()
2727
'property2' => 'value2',
2828
];
2929

30-
$api = $this->getApiMock(CustomProperties::class);
30+
$api = $this->getApiMock();
3131
$api->expects($this->once())
3232
->method('get')
3333
->with('/repos/owner/repo/properties/values')
@@ -44,19 +44,19 @@ public function testShowPropertyDoesNotExist()
4444
'property2' => 'value2',
4545
];
4646

47-
$api = $this->getApiMock(CustomProperties::class);
47+
$api = $this->getApiMock();
4848
$api->expects($this->once())
4949
->method('get')
5050
->with('/repos/owner/repo/properties/values')
5151
->willReturn($allProperties);
5252

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

5656
$api->show('owner', 'repo', 'property3');
5757
}
5858

59-
public function testCreateOrUpdate()
59+
public function testUpdate()
6060
{
6161
$params = [
6262
'property1' => 'newValue1',
@@ -68,13 +68,13 @@ public function testCreateOrUpdate()
6868
'property2' => 42,
6969
];
7070

71-
$api = $this->getApiMock(CustomProperties::class);
71+
$api = $this->getApiMock();
7272
$api->expects($this->once())
7373
->method('patch')
7474
->with('/repos/owner/repo/properties/values', $params)
7575
->willReturn($expectedResponse);
7676

77-
$this->assertEquals($expectedResponse, $api->createOrUpdate('owner', 'repo', $params));
77+
$this->assertEquals($expectedResponse, $api->update('owner', 'repo', $params));
7878
}
7979

8080
protected function getApiClass()

0 commit comments

Comments
 (0)