mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
Fix auto-deployment branch (#506)
This commit is contained in:
@ -29,7 +29,8 @@ public function __invoke(Request $request)
|
||||
->firstOrFail();
|
||||
|
||||
foreach ($gitHook->actions as $action) {
|
||||
if ($action == 'deploy') {
|
||||
$webhookBranch = $gitHook->site->sourceControl->provider()->getWebhookBranch($request->array());
|
||||
if ($action == 'deploy' && $gitHook->site->branch === $webhookBranch) {
|
||||
try {
|
||||
app(Deploy::class)->run($gitHook->site);
|
||||
} catch (SourceControlIsNotConnected) {
|
||||
|
@ -70,4 +70,9 @@ protected function handleResponseErrors(Response $res, string $repo): void
|
||||
throw new RepositoryPermissionDenied($repo);
|
||||
}
|
||||
}
|
||||
|
||||
public function getWebhookBranch(array $payload): string
|
||||
{
|
||||
return str($payload['ref'] ?? '')->after('refs/heads/')->toString();
|
||||
}
|
||||
}
|
||||
|
@ -183,4 +183,9 @@ private function getAuthenticationHeaders(): array
|
||||
'Authorization' => 'Basic '.$basicAuth,
|
||||
];
|
||||
}
|
||||
|
||||
public function getWebhookBranch(array $payload): string
|
||||
{
|
||||
return data_get($payload, 'push.changes.0.new.name', 'default-branch');
|
||||
}
|
||||
}
|
||||
|
@ -176,4 +176,9 @@ public function getApiUrl(): string
|
||||
|
||||
return $host.$this->apiVersion;
|
||||
}
|
||||
|
||||
public function getWebhookBranch(array $payload): string
|
||||
{
|
||||
return $payload['ref'] ?? '';
|
||||
}
|
||||
}
|
||||
|
@ -36,4 +36,6 @@ public function getLastCommit(string $repo, string $branch): ?array;
|
||||
* @throws FailedToDeployGitKey
|
||||
*/
|
||||
public function deployKey(string $title, string $repo, string $key): void;
|
||||
|
||||
public function getWebhookBranch(array $payload): string;
|
||||
}
|
||||
|
Reference in New Issue
Block a user