From 4db4dece714288a3252bfe343ee615f343452f68 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Thu, 29 May 2025 18:24:43 +0530 Subject: [PATCH] Check if resource exists and is connected before adding comment --- app/controllers/api/vcs.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 588ca417cf..4e0b8c66aa 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -123,7 +123,11 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $latestCommentId = ''; - if (!empty($providerPullRequestId) && $resource->getAttribute('providerSilentMode', false) === false) { + // Check if VCS is still connected and resource exists before creating/updating comments + $resourceExists = !$resource->isEmpty(); + $isVcsConnected = !empty($resource->getAttribute('providerRepositoryId', '')); + + if ($resourceExists && $isVcsConnected && !empty($providerPullRequestId) && $resource->getAttribute('providerSilentMode', false) === false) { $latestComment = Authorization::skip(fn () => $dbForPlatform->findOne('vcsComments', [ Query::equal('providerRepositoryId', [$providerRepositoryId]), Query::equal('providerPullRequestId', [$providerPullRequestId]), @@ -166,7 +170,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId ]))); } } - } elseif (!empty($providerBranch)) { + } elseif ($resourceExists && $isVcsConnected && !empty($providerBranch)) { $latestComments = Authorization::skip(fn () => $dbForPlatform->find('vcsComments', [ Query::equal('providerRepositoryId', [$providerRepositoryId]), Query::equal('providerBranch', [$providerBranch]),