refactoring

This commit is contained in:
Saeed Vaziry
2023-08-06 17:36:39 +02:00
parent 643318fcfc
commit a8295e15c3
28 changed files with 239 additions and 66 deletions

View File

@ -3,7 +3,11 @@
namespace App\SourceControlProviders;
use App\Exceptions\FailedToDeployGitHook;
use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\FailedToDestroyGitHook;
use App\Exceptions\RepositoryNotFound;
use App\Exceptions\RepositoryPermissionDenied;
use App\Exceptions\SourceControlIsNotConnected;
use Exception;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
@ -102,9 +106,22 @@ public function getLastCommit(string $repo, string $branch): ?array
return null;
}
/**
* @throws FailedToDeployGitKey
*/
public function deployKey(string $title, string $repo, string $key): void
{
// TODO: Implement deployKey() method.
$res = Http::withToken($this->sourceControl->access_token)->post(
$this->apiUrl."/repositories/$repo/deploy-keys",
[
'label' => $title,
'key' => $key,
]
);
if ($res->status() != 201) {
throw new FailedToDeployGitKey($res->json()['error']['message']);
}
}
protected function getCommitter(string $raw): array

View File

@ -125,7 +125,7 @@ public function deployKey(string $title, string $repo, string $key): void
$response = Http::withToken($this->sourceControl->access_token)->post(
$this->apiUrl.'/projects/'.$repository.'/deploy_keys',
[
'title' => 'deploy-key',
'title' => $title,
'key' => $key,
'can_push' => true,
]