-
-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathCustomProperties.php
More file actions
63 lines (55 loc) · 1.96 KB
/
CustomProperties.php
File metadata and controls
63 lines (55 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Exception\RuntimeException;
/**
* @link https://docs.github.com/en/rest/repos/custom-properties
*
* @author Ondřej Nyklíček <ondrej@nyoncode.cz>
*/
class CustomProperties extends AbstractApi
{
/**
* @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');
}
/**
* @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.
*
* @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)) {
throw new RuntimeException('Unexpected response from GitHub API.');
}
foreach ($allProperties as $property => $value) {
if ($property === $propertyName) {
return ['property_name' => $property, 'value' => $value];
}
}
throw new RuntimeException("Property [$propertyName] not found.");
}
/**
* @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);
}
}