mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
refactoring
This commit is contained in:
@ -33,9 +33,9 @@ public function getRepo(string $repo = null): mixed
|
||||
return $res->json();
|
||||
}
|
||||
|
||||
public function fullRepoUrl(string $repo): string
|
||||
public function fullRepoUrl(string $repo, string $key): string
|
||||
{
|
||||
return "https://x-token-auth:{$this->sourceControl->access_token}@bitbucket.org/$repo.git";
|
||||
return sprintf("git@bitbucket.org-%s:%s.git", $key, $repo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,6 +102,11 @@ public function getLastCommit(string $repo, string $branch): ?array
|
||||
return null;
|
||||
}
|
||||
|
||||
public function deployKey(string $title, string $repo, string $key): void
|
||||
{
|
||||
// TODO: Implement deployKey() method.
|
||||
}
|
||||
|
||||
protected function getCommitter(string $raw): array
|
||||
{
|
||||
$committer = explode(' <', $raw);
|
||||
|
@ -14,7 +14,7 @@ public function getRepo(string $repo = null): string
|
||||
return '';
|
||||
}
|
||||
|
||||
public function fullRepoUrl(string $repo): string
|
||||
public function fullRepoUrl(string $repo, string $key): string
|
||||
{
|
||||
return $repo;
|
||||
}
|
||||
@ -33,4 +33,9 @@ public function getLastCommit(string $repo, string $branch): ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function deployKey(string $title, string $repo, string $key): void
|
||||
{
|
||||
// TODO: Implement deployKey() method.
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\SourceControlProviders;
|
||||
|
||||
use App\Exceptions\FailedToDeployGitKey;
|
||||
use App\Exceptions\FailedToDeployGitHook;
|
||||
use App\Exceptions\FailedToDestroyGitHook;
|
||||
use Exception;
|
||||
@ -41,9 +42,9 @@ public function getRepo(string $repo = null): mixed
|
||||
return $res->json();
|
||||
}
|
||||
|
||||
public function fullRepoUrl(string $repo): string
|
||||
public function fullRepoUrl(string $repo, string $key): string
|
||||
{
|
||||
return "https://{$this->sourceControl->access_token}@github.com/$repo.git";
|
||||
return sprintf("git@github.com-%s:%s.git", $key, $repo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,4 +118,25 @@ public function getLastCommit(string $repo, string $branch): ?array
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FailedToDeployGitKey
|
||||
*/
|
||||
public function deployKey(string $title, string $repo, string $key): void
|
||||
{
|
||||
$response = Http::withToken($this->sourceControl->access_token)->post(
|
||||
$this->apiUrl.'/repos/'.$repo.'/keys',
|
||||
[
|
||||
'title' => $title,
|
||||
'key' => $key,
|
||||
'read_only' => false,
|
||||
]
|
||||
);
|
||||
|
||||
info('github response', $response->json());
|
||||
|
||||
if ($response->status() != 201) {
|
||||
throw new FailedToDeployGitKey(json_decode($response->body())->message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\SourceControlProviders;
|
||||
|
||||
use App\Exceptions\FailedToDeployGitKey;
|
||||
use App\Exceptions\FailedToDeployGitHook;
|
||||
use App\Exceptions\FailedToDestroyGitHook;
|
||||
use Exception;
|
||||
@ -33,9 +34,9 @@ public function getRepo(string $repo = null): mixed
|
||||
return $res->json();
|
||||
}
|
||||
|
||||
public function fullRepoUrl(string $repo): string
|
||||
public function fullRepoUrl(string $repo, string $key): string
|
||||
{
|
||||
return 'https://oauth2:'.$this->sourceControl->access_token.'@gitlab.com/'.$repo.'.git';
|
||||
return sprintf("git@gitlab.com-%s:%s.git", $key, $repo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,4 +115,24 @@ public function getLastCommit(string $repo, string $branch): ?array
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FailedToDeployGitKey
|
||||
*/
|
||||
public function deployKey(string $title, string $repo, string $key): void
|
||||
{
|
||||
$repository = urlencode($repo);
|
||||
$response = Http::withToken($this->sourceControl->access_token)->post(
|
||||
$this->apiUrl.'/projects/'.$repository.'/deploy_keys',
|
||||
[
|
||||
'title' => 'deploy-key',
|
||||
'key' => $key,
|
||||
'can_push' => true,
|
||||
]
|
||||
);
|
||||
|
||||
if ($response->status() != 201) {
|
||||
throw new FailedToDeployGitKey(json_decode($response->body())->message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user