mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Delete vcs documents from collections on Uninstallation event
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user