-
-
Notifications
You must be signed in to change notification settings - Fork 404
Expand file tree
/
Copy pathAbstractSourceControlProvider.php
More file actions
executable file
·78 lines (64 loc) · 1.95 KB
/
AbstractSourceControlProvider.php
File metadata and controls
executable file
·78 lines (64 loc) · 1.95 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
<?php
namespace App\SourceControlProviders;
use App\Exceptions\RepositoryNotFound;
use App\Exceptions\RepositoryPermissionDenied;
use App\Exceptions\SourceControlIsNotConnected;
use App\Models\SourceControl;
use Illuminate\Http\Client\Response;
abstract class AbstractSourceControlProvider implements SourceControlProvider
{
public function __construct(protected SourceControl $sourceControl) {}
public function createRules(array $input): array
{
return [
'token' => 'required',
];
}
public function createData(array $input): array
{
return [
'token' => $input['token'] ?? '',
];
}
public function data(): array
{
// support for older data
$token = $this->sourceControl->access_token ?? '';
return [
'token' => $this->sourceControl->provider_data['token'] ?? $token,
];
}
/**
* @throws SourceControlIsNotConnected
* @throws RepositoryNotFound
* @throws RepositoryPermissionDenied
*/
protected function handleResponseErrors(Response $res, string $repo): void
{
if ($res->status() == 401) {
throw new SourceControlIsNotConnected($this->sourceControl);
}
if ($res->status() == 404) {
throw new RepositoryNotFound($repo);
}
if ($res->status() == 403) {
throw new RepositoryPermissionDenied($repo);
}
}
public function getWebhookBranch(array $payload): string
{
return str($payload['ref'] ?? '')->after('refs/heads/')->toString();
}
public function getRepos(bool $useCache = true): array
{
return [];
}
public function getBranches(string $repo, bool $useCache = true): array
{
return [];
}
public function getSshPort(): ?int
{
return (int) $this->sourceControl->port ?: ((int) ($this->sourceControl->provider_data['port'] ?? null) ?: null);
}
}