-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add core installation event handler
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { EmitterWebhookEvent } from "@ijsblokje/server"; | ||
import { ApplyOptions, GitHubEvent } from "../index.js"; | ||
|
||
@ApplyOptions({ event: "installation" }) | ||
export default class extends GitHubEvent { | ||
public override async run(event: EmitterWebhookEvent<"installation">) { | ||
switch (event.payload.action) { | ||
case "created": | ||
case "unsuspend": | ||
await this.create(event as any); | ||
break; | ||
case "deleted": | ||
case "suspend": | ||
this.octocat.installations.cache.delete(event.payload.installation.id); | ||
break; | ||
case "new_permissions_accepted": | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* Registers the new installation | ||
* @param event The installation.create event data | ||
*/ | ||
private async create(event: EmitterWebhookEvent<"installation.created" | "installation.suspend">) { | ||
const manager = this.octocat.installations; | ||
if (manager.allowedInstallations && !manager.allowedInstallations.includes(event.payload.installation.account.login)) return; | ||
|
||
await manager.loadInstallation(event.payload.installation as any); | ||
} | ||
} |