Skip to content

Commit a3a1ff6

Browse files
committed
fix: preview deployments should be stopped properly via gh webhook
1 parent 5df7e23 commit a3a1ff6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/Http/Controllers/Webhook/Github.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ public function normal(Request $request)
340340
return response("Nothing to do. No applications found with branch '$base_branch'.");
341341
}
342342
}
343-
344343
foreach ($applications as $application) {
345344
$isFunctional = $application->destination->server->isFunctional();
346345
if (! $isFunctional) {
@@ -432,8 +431,13 @@ public function normal(Request $request)
432431
if ($action === 'closed' || $action === 'close') {
433432
$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();
434433
if ($found) {
435-
$container_name = generateApplicationContainerName($application, $pull_request_id);
436-
instant_remote_process(["docker rm -f $container_name"], $application->destination->server);
434+
$containers = getCurrentApplicationContainerStatus($application->destination->server, $application->id, $pull_request_id);
435+
if ($containers->isNotEmpty()) {
436+
$containers->each(function ($container) use ($application) {
437+
$container_name = data_get($container, 'Names');
438+
instant_remote_process(["docker rm -f $container_name"], $application->destination->server);
439+
});
440+
}
437441

438442
ApplicationPullRequestUpdateJob::dispatchSync(application: $application, preview: $found, status: ProcessStatus::CLOSED);
439443
$found->delete();

0 commit comments

Comments
 (0)