generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
728 additions
and
644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ on: | |
description: "Auth Token" | ||
ref: | ||
description: "Ref" | ||
command: | ||
required: true | ||
|
||
jobs: | ||
compute: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,24 @@ | ||
import * as core from "@actions/core"; | ||
import * as github from "@actions/github"; | ||
import { Octokit } from "@octokit/rest"; | ||
import { Value } from "@sinclair/typebox/build/cjs/value"; | ||
import { envSchema, pluginSettingsSchema, PluginInputs, pluginSettingsValidator } from "./types"; | ||
import { createActionsPlugin } from "@ubiquity-os/plugin-sdk"; | ||
import { createAdapters } from "./adapters"; | ||
import { SupportedEvents } from "./types/context"; | ||
import { Env, envSchema } from "./types/env"; | ||
import { PluginSettings, pluginSettingsSchema } from "./types/plugin-inputs"; | ||
import { Command } from "./types/command"; | ||
import { plugin } from "./plugin"; | ||
|
||
/** | ||
* How a GitHub action executes the plugin. | ||
*/ | ||
export async function run() { | ||
const payload = github.context.payload.inputs; | ||
|
||
const env = Value.Decode(envSchema, payload.env); | ||
const settings = Value.Decode(pluginSettingsSchema, Value.Default(pluginSettingsSchema, JSON.parse(payload.settings))); | ||
|
||
if (!pluginSettingsValidator.test(settings)) { | ||
throw new Error("Invalid settings provided"); | ||
import { LogLevel } from "@ubiquity-os/ubiquity-os-logger"; | ||
|
||
createActionsPlugin<PluginSettings, Env, Command, SupportedEvents>( | ||
(context) => { | ||
return plugin({ | ||
...context, | ||
adapters: {} as ReturnType<typeof createAdapters>, | ||
}); | ||
}, | ||
{ | ||
envSchema: envSchema, | ||
postCommentOnError: true, | ||
settingsSchema: pluginSettingsSchema, | ||
logLevel: (process.env.LOG_LEVEL as LogLevel) ?? "info", | ||
kernelPublicKey: process.env.KERNEL_PUBLIC_KEY, | ||
} | ||
|
||
const inputs: PluginInputs = { | ||
stateId: payload.stateId, | ||
eventName: payload.eventName, | ||
eventPayload: JSON.parse(payload.eventPayload), | ||
settings, | ||
authToken: payload.authToken, | ||
ref: payload.ref, | ||
}; | ||
|
||
await plugin(inputs, env); | ||
|
||
return returnDataToKernel(inputs.authToken, inputs.stateId, {}); | ||
} | ||
|
||
async function returnDataToKernel(repoToken: string, stateId: string, output: object) { | ||
const octokit = new Octokit({ auth: repoToken }); | ||
await octokit.repos.createDispatchEvent({ | ||
owner: github.context.repo.owner, | ||
repo: github.context.repo.repo, | ||
event_type: "return_data_to_ubiquibot_kernel", | ||
client_payload: { | ||
state_id: stateId, | ||
output: JSON.stringify(output), | ||
}, | ||
}); | ||
} | ||
|
||
run() | ||
.then((result) => { | ||
core.setOutput("result", result); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
core.setFailed(error); | ||
}); | ||
).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { StaticDecode, Type as T } from "@sinclair/typebox"; | ||
|
||
export const commandSchema = T.Object({ | ||
name: T.Literal("wallet"), | ||
parameters: T.Object({ | ||
walletAddress: T.String(), | ||
}), | ||
}); | ||
|
||
export type Command = StaticDecode<typeof commandSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,11 @@ | ||
import { Octokit } from "@octokit/rest"; | ||
import { EmitterWebhookEvent as WebhookEvent, EmitterWebhookEventName as WebhookEventName } from "@octokit/webhooks"; | ||
import { Logs } from "@ubiquity-os/ubiquity-os-logger"; | ||
import { createAdapters } from "../adapters"; | ||
import { Env } from "./env"; | ||
import { PluginSettings } from "./plugin-inputs"; | ||
import { Context as PluginContext } from "@ubiquity-os/plugin-sdk"; | ||
import { Command } from "./command"; | ||
|
||
export type SupportedEventsU = "issue_comment.created"; | ||
export type SupportedEvents = "issue_comment.created"; | ||
|
||
export type SupportedEvents = { | ||
[K in SupportedEventsU]: K extends WebhookEventName ? WebhookEvent<K> : never; | ||
}; | ||
|
||
export interface Context<T extends SupportedEventsU = SupportedEventsU, TU extends SupportedEvents[T] = SupportedEvents[T]> { | ||
eventName: T; | ||
payload: TU["payload"]; | ||
octokit: InstanceType<typeof Octokit>; | ||
export type Context<TEvents extends SupportedEvents = SupportedEvents> = PluginContext<PluginSettings, Env, Command, TEvents> & { | ||
adapters: ReturnType<typeof createAdapters>; | ||
config: PluginSettings; | ||
env: Env; | ||
logger: Logs; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import { Type as T } from "@sinclair/typebox"; | ||
import { StaticDecode } from "@sinclair/typebox"; | ||
import "dotenv/config"; | ||
import { StandardValidator } from "typebox-validators"; | ||
|
||
export const envSchema = T.Object({ | ||
SUPABASE_URL: T.String(), | ||
SUPABASE_KEY: T.String(), | ||
KERNEL_PUBLIC_KEY: T.Optional(T.String()), | ||
LOG_LEVEL: T.Optional(T.String()), | ||
}); | ||
|
||
export const envValidator = new StandardValidator(envSchema); | ||
|
||
export type Env = StaticDecode<typeof envSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.