-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFetchWebhook.php
More file actions
50 lines (43 loc) · 1.37 KB
/
FetchWebhook.php
File metadata and controls
50 lines (43 loc) · 1.37 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
<?php
namespace App\Actions\Github\Webhook;
use App\Models\Webhook;
use ReflectionException;
use App\Models\Repository;
use Saloon\Contracts\Response;
use App\Actions\Github\GithubAction;
use Saloon\Exceptions\PendingRequestException;
use Saloon\Exceptions\InvalidResponseClassException;
use App\Http\Integrations\Github\Repository\Requests\GetRepositoryWebhooks;
use App\Models\PullRequest;
class FetchWebhook
{
use GithubAction;
/**
* @throws InvalidResponseClassException
* @throws ReflectionException
* @throws PendingRequestException
*/
public function execute(Webhook $webhook, Repository|PullRequest $model): Response
{
[
'username' => $username,
'repository' => $repository,
] = $this->getUsernameAndRepository($model);
$request = new GetRepositoryWebhooks(
username: $username,
repository: $repository,
hookId: $webhook->hook_id
);
return $this->connector->send($request);
}
public function getUsernameAndRepository(Repository|PullRequest $model): array
{
if ($model instanceof Repository) {
return [
'username' => $model->username,
'repository' => $model->repository_name,
];
}
return app(PullRequestService::class)->getRegexMatch($model->html_url);
}
}