Skip to content

Commit

Permalink
feat: add core installation event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsKoud committed Jun 21, 2023
1 parent 8e50f4f commit 5510791
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/octocat/src/core/InstallationEvent.ts
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);
}
}

0 comments on commit 5510791

Please sign in to comment.