generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 9
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
17 changed files
with
748 additions
and
714 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 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { Config } from "jest"; | ||
|
||
const cfg: Config = { | ||
transform: { | ||
"^.+\\.tsx?$": [ | ||
"ts-jest", | ||
{ | ||
useESM: true, | ||
}, | ||
], | ||
}, | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
coveragePathIgnorePatterns: ["node_modules", "mocks"], | ||
collectCoverage: true, | ||
coverageReporters: ["json", "lcov", "text", "clover", "json-summary"], | ||
reporters: ["default", "jest-junit", "jest-md-dashboard"], | ||
coverageDirectory: "coverage", | ||
testTimeout: 20000, | ||
roots: ["<rootDir>", "tests"], | ||
extensionsToTreatAsEsm: [".ts"], | ||
moduleNameMapper: { | ||
"^(\\.{1,2}/.*)\\.js$": "$1", | ||
}, | ||
setupFilesAfterEnv: ["dotenv/config"], | ||
}; | ||
|
||
export default cfg; |
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 |
---|---|---|
@@ -1,40 +1,19 @@ | ||
import * as github from "@actions/github"; | ||
import { Octokit } from "@octokit/rest"; | ||
import { validateAndDecodeSchemas } from "./helpers/validator"; | ||
import { createActionsPlugin } from "@ubiquity-os/plugin-sdk"; | ||
import { SupportedEvents } from "./types/context"; | ||
import { Env, envSchema } from "./types/env"; | ||
import { PluginSettings, pluginSettingsSchema } from "./types/plugin-inputs"; | ||
import { plugin } from "./plugin"; | ||
import { PluginInputs } from "./types"; | ||
import { LogLevel } from "@ubiquity-os/ubiquity-os-logger"; | ||
|
||
/** | ||
* How a GitHub action executes the plugin. | ||
*/ | ||
export async function run() { | ||
const payload = github.context.payload.inputs; | ||
|
||
payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; | ||
const { decodedSettings, decodedEnv } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); | ||
const inputs: PluginInputs = { | ||
stateId: payload.stateId, | ||
eventName: payload.eventName, | ||
eventPayload: JSON.parse(payload.eventPayload), | ||
settings: decodedSettings, | ||
authToken: payload.authToken, | ||
ref: payload.ref, | ||
}; | ||
|
||
await plugin(inputs, decodedEnv); | ||
|
||
return returnDataToKernel(process.env.GITHUB_TOKEN, inputs.stateId, {}); | ||
} | ||
|
||
export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return-data-to-ubiquity-os-kernel") { | ||
const octokit = new Octokit({ auth: repoToken }); | ||
return octokit.repos.createDispatchEvent({ | ||
owner: github.context.repo.owner, | ||
repo: github.context.repo.repo, | ||
event_type: eventType, | ||
client_payload: { | ||
state_id: stateId, | ||
output: JSON.stringify(output), | ||
}, | ||
}); | ||
} | ||
createActionsPlugin<PluginSettings, Env, null, SupportedEvents>( | ||
(context) => { | ||
return plugin(context); | ||
}, | ||
{ | ||
envSchema: envSchema, | ||
postCommentOnError: true, | ||
settingsSchema: pluginSettingsSchema, | ||
logLevel: (process.env.LOG_LEVEL as LogLevel) ?? "info", | ||
kernelPublicKey: process.env.KERNEL_PUBLIC_KEY, | ||
} | ||
).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
This file was deleted.
Oops, something went wrong.
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,25 +1,10 @@ | ||
import { paginateRest } from "@octokit/plugin-paginate-rest"; | ||
import { Octokit } from "@octokit/rest"; | ||
import { Logs } from "@ubiquity-dao/ubiquibot-logger"; | ||
import { updatePullRequests } from "./helpers/update-pull-requests"; | ||
import { Context, Env, PluginInputs } from "./types"; | ||
import { Context } from "./types"; | ||
|
||
/** | ||
* How a worker executes the plugin. | ||
*/ | ||
export async function plugin(inputs: PluginInputs, env: Env) { | ||
const octokitWithPlugin = Octokit.plugin(paginateRest); | ||
const octokit = new octokitWithPlugin({ auth: inputs.authToken }); | ||
|
||
const context: Context = { | ||
eventName: inputs.eventName, | ||
payload: inputs.eventPayload, | ||
config: inputs.settings, | ||
octokit, | ||
env, | ||
logger: new Logs("debug"), | ||
}; | ||
|
||
export async function plugin(context: Context) { | ||
context.logger.info("Will check the following repos", { ...context.config.repos }); | ||
return await updatePullRequests(context); | ||
} |
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,20 +1,7 @@ | ||
import { Octokit } from "@octokit/rest"; | ||
import { EmitterWebhookEvent as WebhookEvent, EmitterWebhookEventName as WebhookEventName } from "@octokit/webhooks"; | ||
import { Logs } from "@ubiquity-dao/ubiquibot-logger"; | ||
import { Context as PluginContext } from "@ubiquity-os/plugin-sdk"; | ||
import { Env } from "./env"; | ||
import { PluginSettings } from "./plugin-inputs"; | ||
|
||
export type SupportedEventsU = "push" | "issue_comment.created"; | ||
export type SupportedEvents = "push" | "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>; | ||
config: PluginSettings; | ||
env: Env; | ||
logger: Logs; | ||
} | ||
export type Context<TEvents extends SupportedEvents = SupportedEvents> = PluginContext<PluginSettings, Env, null, TEvents>; |
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,12 +1,9 @@ | ||
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({ | ||
workflowName: 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.