Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fixed github app deleting private key when it is used by other resources

ShadowArcanist97e734e5ea59
diff --git a/app/Models/GithubApp.php b/app/Models/GithubApp.php
index 0d643306c9..ab82c9a9ce 100644
--- a/app/Models/GithubApp.php
+++ b/app/Models/GithubApp.php
@@ -28,7 +28,20 @@ class GithubApp extends BaseModel
if ($applications_count > 0) {
throw new \Exception('You cannot delete this GitHub App because it is in use by '.$applications_count.' application(s). Delete them first.');
}
- $github_app->privateKey()->delete();
+
+ $privateKey = $github_app->privateKey;
+ if ($privateKey) {
+ // Check if key is used by anything EXCEPT this GitHub app
+ $isUsedElsewhere = $privateKey->servers()->exists()
+ || $privateKey->applications()->exists()
+ || $privateKey->githubApps()->where('id', '!=', $github_app->id)->exists()
+ || $privateKey->gitlabApps()->exists();
+
+ if (! $isUsedElsewhere) {
+ $privateKey->delete();
+ } else {
+ }
+ }
});
}