generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.ts
51 lines (45 loc) · 1.62 KB
/
plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Context } from "./types/context";
import { Octokit } from "@octokit/rest";
import { createClient } from "@supabase/supabase-js";
import { createAdapters } from "./adapters";
import { Database } from "./adapters/supabase/types/database";
import { doSomething } from "./handlers/handler";
import { Env, PluginInputs } from "./types";
/**
* How a worker executes the plugin.
*/
export async function plugin(inputs: PluginInputs, env: Env) {
const octokit = new Octokit({ auth: inputs.authToken });
const supabase = createClient<Database>(env.SUPABASE_URL, env.SUPABASE_KEY);
const context: Context = {
eventName: inputs.eventName,
payload: inputs.eventPayload,
config: inputs.settings,
octokit,
env,
logger: {
debug(message: unknown, ...optionalParams: unknown[]) {
console.debug(message, ...optionalParams);
},
info(message: unknown, ...optionalParams: unknown[]) {
console.log(message, ...optionalParams);
},
warn(message: unknown, ...optionalParams: unknown[]) {
console.warn(message, ...optionalParams);
},
error(message: unknown, ...optionalParams: unknown[]) {
console.error(message, ...optionalParams);
},
fatal(message: unknown, ...optionalParams: unknown[]) {
console.error(message, ...optionalParams);
},
},
adapters: {} as ReturnType<typeof createAdapters>,
};
context.adapters = createAdapters(supabase, context);
if (context.eventName === "issue_comment.created") {
await doSomething(context);
} else {
context.logger.error(`Unsupported event: ${context.eventName}`);
}
}