Github integration (#6414)

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Apoorv Mishra
2024-03-23 19:39:28 +05:30
committed by GitHub
parent a648625700
commit 450d0d9355
47 changed files with 1710 additions and 93 deletions

View File

@@ -0,0 +1,24 @@
import { IntegrationType } from "@shared/types";
import { Integration } from "@server/models";
import BaseProcessor from "@server/queues/processors/BaseProcessor";
import { IntegrationEvent, Event } from "@server/types";
import { CacheHelper } from "@server/utils/CacheHelper";
export default class IntegrationCreatedProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = ["integrations.create"];
async perform(event: IntegrationEvent) {
const integration = await Integration.findOne({
where: {
id: event.modelId,
},
paranoid: false,
});
if (integration?.type !== IntegrationType.Embed) {
return;
}
// Clear the cache of unfurled data for the team as it may be stale now.
await CacheHelper.clearData(CacheHelper.getUnfurlKey(integration.teamId));
}
}

View File

@@ -0,0 +1,34 @@
import { IntegrationType } from "@shared/types";
import { Integration } from "@server/models";
import BaseProcessor from "@server/queues/processors/BaseProcessor";
import { IntegrationEvent, Event } from "@server/types";
import { CacheHelper } from "@server/utils/CacheHelper";
import { Hook, PluginManager } from "@server/utils/PluginManager";
export default class IntegrationDeletedProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = ["integrations.delete"];
async perform(event: IntegrationEvent) {
const integration = await Integration.findOne({
where: {
id: event.modelId,
},
paranoid: false,
});
if (!integration) {
return;
}
const uninstallHooks = PluginManager.getHooks(Hook.Uninstall);
for (const hook of uninstallHooks) {
await hook.value(integration);
}
// Clear the cache of unfurled data for the team as it may be stale now.
if (integration.type === IntegrationType.Embed) {
await CacheHelper.clearData(CacheHelper.getUnfurlKey(integration.teamId));
}
await integration.destroy({ force: true });
}
}