Delete vcs documents from collections on Uninstallation event

This commit is contained in:
Khushboo Verma
2023-04-12 18:25:02 +05:30
parent b86adcb28f
commit 3e5e20fa90
3 changed files with 37 additions and 1 deletions
+11
View File
@@ -555,6 +555,17 @@ $collections = [
'$id' => ID::custom('vcs_repos'),
'name' => 'vcs_repos',
'attributes' => [
[
'$id' => ID::custom('vcsInstallationId'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => true,
'default' => null,
'array' => false,
'filters' => []
],
[
'$id' => ID::custom('projectId'),
'type' => Database::VAR_STRING,
+8
View File
@@ -527,6 +527,13 @@ App::put('/v1/functions/:functionId')
$branchName = "main";
$code = $github->generateGitCloneCommand($repositoryId, $branchName);
$vcsInstallations = $dbForConsole->findOne('vcs_installations', [
Query::equal('projectId', [$project->getId()]),
Query::equal('provider', ["GitHub"]),
Query::limit(100),
]);
$vcsInstallationsId = $vcsInstallations->getId();
//Add document in VCS map collection
$vcs_repos = new Document([
'$id' => ID::unique(),
@@ -535,6 +542,7 @@ App::put('/v1/functions/:functionId')
Permission::update(Role::any()),
Permission::delete(Role::any()),
],
'vcsInstallationId' => $vcsInstallationsId,
'projectId' => $project->getId(),
'projectInternalId' => $projectInternalId,
'repositoryId' => $repositoryId,
+18 -1
View File
@@ -191,7 +191,24 @@ App::post('/v1/vcs/github/incomingwebhook')
}
} else if ($event == $github::EVENT_INSTALLATION) {
$installationId = $parsedPayload["installationId"];
// delete documents from all respective collections
$vcsInstallations = $dbForConsole->find('vcs_installations', [
Query::equal('installationId', [$installationId]),
Query::limit(1000)
]);
foreach ($vcsInstallations as $installation) {
$vcsRepos = $dbForConsole->find('vcs_repos', [
Query::equal('vcsInstallationId', [$installation->getId()]),
Query::limit(1000)
]);
foreach ($vcsRepos as $repo) {
$dbForConsole->deleteDocument('vcs_repos', $repo->getId());
}
$dbForConsole->deleteDocument('vcs_installations', $installation->getId());
}
} else if ($event == $github::EVENT_PULL_REQUEST) {
// find last push to this branch
}