generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.ts
50 lines (43 loc) · 1.44 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
import { Octokit } from "@octokit/rest";
import { returnDataToKernel } from "./helpers/validator";
import { Env, PluginInputs } from "./types";
import { Context } from "./types";
import { isIssueCommentEvent } from "./types/typeguards";
import { helloWorld } from "./handlers/hello-world";
import { LogLevel, Logs } from "@ubiquity-dao/ubiquibot-logger";
/**
* The main plugin function. Split for easier testing.
*/
export async function runPlugin(context: Context) {
const { logger, eventName } = context;
if (isIssueCommentEvent(context)) {
return await helloWorld(context);
}
logger.error(`Unsupported event: ${eventName}`);
}
/**
* How a worker executes the plugin.
*/
export async function plugin(inputs: PluginInputs, env: Env) {
const octokit = new Octokit({ auth: inputs.authToken });
const context: Context = {
eventName: inputs.eventName,
payload: inputs.eventPayload,
config: inputs.settings,
octokit,
env,
logger: new Logs("info" as LogLevel),
};
/**
* NOTICE: Consider non-database storage solutions unless necessary
*
* Initialize storage adapters here. For example, to use Supabase:
*
* import { createClient } from "@supabase/supabase-js";
*
* const supabase = createClient(env.SUPABASE_URL, env.SUPABASE_KEY);
* context.adapters = createAdapters(supabase, context);
*/
await runPlugin(context);
return returnDataToKernel(process.env.GITHUB_TOKEN, inputs.stateId, {});
}