diff --git a/main.ts b/main.ts index b7dcecd..2413356 100644 --- a/main.ts +++ b/main.ts @@ -21,7 +21,7 @@ export type ServiceResponse = { type ServiceList = { // deno-lint-ignore no-explicit-any - [route: string]: (body: any, request: any) => Promise; + [route: string]: (body: any, request: any) => (Promise | ServiceResponse); }; // deno-lint-ignore no-explicit-any diff --git a/nexus/mod.ts b/nexus/mod.ts new file mode 100644 index 0000000..9d67d0c --- /dev/null +++ b/nexus/mod.ts @@ -0,0 +1,92 @@ +import { HandlerList, kv, NoMessage, ServiceResponse } from "../main.ts"; +import { WebhookMessage } from "https://deno.land/x/dishooks@v1.1.0/types.ts"; + +export type GithubMessage = { + message: WebhookMessage; + repo: string; +}; + +const allowedRepositories = [ + "thatgravyboat", +]; + +const groupArtifactRegex: { [route: string]: string | boolean } = { + "tech.thatgravyboat": "skyblock-api.*|repo-lib", + "me.owdding": true, +}; + +enum actions { + CREATED = "CREATED", + DELETED = "DELETED", + UPDATED = "UPDATED", +} + +type request = { + timestamp: string; + nodeId: string; + initiator: string; + repositoryName: string; + action: actions; + component: Component; +}; + +type Component = mavenComponent; + +enum componentFormat { + MAVEN = "maven2", +} + +interface baseComponent { + id: string; + componentId: string; + format: componentFormat; +} + +interface mavenComponent extends baseComponent { + format: componentFormat.MAVEN; + name: string; + group: string; + version: string; +} + +export const Nexus = ( + //deno-lint-ignore no-explicit-any + _body: any, + //deno-lint-ignore no-explicit-any + _request: any, +): ServiceResponse | undefined => { + const body: request = _body; + + if (body.action != actions.CREATED) return; + if (!(body.repositoryName.toLowerCase() in allowedRepositories)) return; + + switch (body.component.format) { + case componentFormat.MAVEN: { + if (!groupArtifactRegex[body.component.group.toLocaleLowerCase()]) return; + const condition = groupArtifactRegex[body.component.group.toLowerCase()]; + + if (typeof condition === "string") { + if (!RegExp(condition).test(body.component.name.toLocaleLowerCase())) return; + } else if (typeof condition === "boolean" && condition !== true) { + return + } else { + return + } + + return { + message: { + embeds: [ + { + title: "New Artifact!", + description: ` + todo but \`${body.component.group}:${body.component.name}:${body.component.version}\` + `, + }, + ], + username: "Nexus", + }, + isRedelivered: false, + }; + } + } +};