Repository navigation
Expand file tree
/
Copy pathIndex.php
More file actions
81 lines (71 loc) · 2.25 KB
/
Copy pathIndex.php
File metadata and controls
81 lines (71 loc) · 2.25 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace JordanPartridge\GithubClient\Requests\Pulls;
use JordanPartridge\GithubClient\Data\Pulls\Params;
use JordanPartridge\GithubClient\Data\Pulls\PullRequestDTO;
use JordanPartridge\GithubClient\ValueObjects\Repo;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
class Index extends Request
{
/**
* The http method for this request.
*/
protected Method $method = Method::GET;
/**
* The repo extracted through the value object.
*/
private string $repo;
/**
* The owner extracted through the value object.
*/
private string $owner;
/**
* The optional parameters for filtering the request results.
*/
private Params $parameters;
/**
* Validate the owner_repo string and set the owner and repo properties.
*
* @see https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28
*
* @param string $owner_repo - eg jordanpartridge/github-client
*/
public function __construct(string $owner_repo, array $parameters = [])
{
$validated = Repo::fromFullName($owner_repo);
$this->owner = $validated->owner();
$this->repo = $validated->name();
$this->parameters = Params::fromArray($parameters);
}
/**
* Resolves the endpoint URL for retrieving all pull requests.
* This should be in the format of: "/repos/{owner}/{repo}/pulls"
*/
public function resolveEndpoint(): string
{
return sprintf('repos/%s/%s/pulls', $this->owner, $this->repo);
}
public function createDtoFromResponse(Response $response): array
{
return array_map(
fn (array $pullRequest) => PullRequestDTO::fromApiResponse($pullRequest),
$response->json(),
);
}
/**
* @return array|array
*/
public function defaultQuery(): array
{
return [
'state' => $this->parameters->state,
'head' => $this->parameters->head,
'base' => $this->parameters->base,
'sort' => $this->parameters->sort?->value,
'direction' => $this->parameters->direction?->value,
'per_page' => $this->parameters->per_page,
'page' => $this->parameters->page,
];
}
}