From c9cbdcd41ef6122851925e13d78932aa6a7a16a5 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:57:19 +0900 Subject: [PATCH 01/14] feat: schema validation --- .github/workflows/validate-schema.yml | 38 ++++++++++++++++++++++++ package.json | 3 +- src/helpers/validator.ts | 38 ++++++++++++++++++++++++ src/types/plugin-inputs.ts | 9 ++++++ src/types/process-env.d.ts | 9 ++++++ src/validate-schema.ts | 42 +++++++++++++++++++++++++++ yarn.lock | 5 ++++ 7 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/validate-schema.yml create mode 100644 src/helpers/validator.ts create mode 100644 src/types/process-env.d.ts create mode 100644 src/validate-schema.ts diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml new file mode 100644 index 0000000..7325b87 --- /dev/null +++ b/.github/workflows/validate-schema.yml @@ -0,0 +1,38 @@ +name: "Validate Schema" + +on: + workflow_dispatch: + inputs: + stateId: + description: "State Id" + eventName: + description: "Event Name" + eventPayload: + description: "Event Payload" + settings: + description: "Settings" + authToken: + description: "Auth Token" + ref: + description: "Ref" + +jobs: + validate: + name: "Validate Schema" + runs-on: ubuntu-latest + permissions: write-all + + steps: + - uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: "20.10.0" + + - name: Install deps and run validation + run: | + yarn install --immutable --immutable-cache --check-cache + yarn tsx src/validate-schema.ts + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index 297b164..e56095d 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ "dotenv": "16.4.5", "luxon": "3.4.4", "ms": "2.1.3", - "tsx": "4.11.2" + "tsx": "4.11.2", + "typebox-validators": "0.3.5" }, "devDependencies": { "@commitlint/cli": "19.3.0", diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts new file mode 100644 index 0000000..9f749c1 --- /dev/null +++ b/src/helpers/validator.ts @@ -0,0 +1,38 @@ +import { TransformDecodeCheckError, TransformDecodeError, Value, ValueError } from "@sinclair/typebox/value"; +import { Env, envSchema, envValidator, pluginSettingsValidator, UserActivityWatcherSettings, userActivityWatcherSettingsSchema } from "../types/plugin-inputs"; + +export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { + const errors: ValueError[] = []; + + const env = Value.Default(envSchema, rawEnv) as Env; + if (!envValidator.test(env)) { + for (const error of envValidator.errors(env)) { + console.error(error); + errors.push(error); + } + } + + const settings = Value.Default(userActivityWatcherSettingsSchema, rawSettings) as UserActivityWatcherSettings; + if (!pluginSettingsValidator.test(settings)) { + for (const error of pluginSettingsValidator.errors(settings)) { + console.error(error); + errors.push(error); + } + } + + if (errors.length) { + throw { errors }; + } + + try { + const decodedSettings = Value.Decode(userActivityWatcherSettingsSchema, settings); + const decodedEnv = Value.Decode(envSchema, rawEnv || {}); + return { decodedEnv, decodedSettings }; + } catch (e) { + console.error("validateAndDecodeSchemas", e); + if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { + throw { errors: [e.error] }; + } + throw e; + } +} diff --git a/src/types/plugin-inputs.ts b/src/types/plugin-inputs.ts index 176046b..4586ee1 100644 --- a/src/types/plugin-inputs.ts +++ b/src/types/plugin-inputs.ts @@ -1,6 +1,7 @@ import { EmitterWebhookEvent as WebhookEvent, EmitterWebhookEventName as WebhookEventName } from "@octokit/webhooks"; import { StaticDecode, StringOptions, Type as T, TypeBoxError } from "@sinclair/typebox"; import ms from "ms"; +import { StandardValidator } from "typebox-validators"; export type SupportedEvents = "pull_request_review_comment.created" | "issue_comment.created" | "push"; @@ -51,4 +52,12 @@ export const userActivityWatcherSettingsSchema = T.Object({ }), }); +export const pluginSettingsValidator = new StandardValidator(userActivityWatcherSettingsSchema); + export type UserActivityWatcherSettings = StaticDecode; + +export const envSchema = T.Object({}); + +export const envValidator = new StandardValidator(envSchema); + +export type Env = StaticDecode; diff --git a/src/types/process-env.d.ts b/src/types/process-env.d.ts new file mode 100644 index 0000000..a2bb98f --- /dev/null +++ b/src/types/process-env.d.ts @@ -0,0 +1,9 @@ +declare global { + namespace NodeJS { + interface ProcessEnv { + GITHUB_TOKEN: string; + } + } +} + +export {}; diff --git a/src/validate-schema.ts b/src/validate-schema.ts new file mode 100644 index 0000000..dfaace2 --- /dev/null +++ b/src/validate-schema.ts @@ -0,0 +1,42 @@ +import * as core from "@actions/core"; +import * as github from "@actions/github"; +import { Octokit } from "@octokit/rest"; +import { validateAndDecodeSchemas } from "./helpers/validator"; + +export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_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), + }, + }); +} + +async function main() { + const payload = github.context.payload.inputs; + + validateAndDecodeSchemas(process.env, JSON.parse(payload.settings)); + return { errors: [], payload }; +} + +main() + .then((payload) => { + console.log("Configuration validated."); + return payload; + }) + .catch((errors) => { + console.error("Failed to validate configuration", errors); + core.setFailed(errors); + return errors; + }) + .then(async (errors) => { + const payload = github.context.payload.inputs; + await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, errors, "configuration_validation"); + }) + .catch((e) => { + console.error("Failed to return the data to the kernel.", e); + }); diff --git a/yarn.lock b/yarn.lock index 6005b1a..152cfff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5189,6 +5189,11 @@ type-fest@^4.9.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.18.3.tgz#5249f96e7c2c3f0f1561625f54050e343f1c8f68" integrity sha512-Q08/0IrpvM+NMY9PA2rti9Jb+JejTddwmwmVQGskAlhtcrw1wsRzoR6ode6mR+OAabNa75w/dxedSUY2mlphaQ== +typebox-validators@0.3.5: + version "0.3.5" + resolved "https://registry.yarnpkg.com/typebox-validators/-/typebox-validators-0.3.5.tgz#b913bad0a87571ffe0edd01d2b6090a268e1ecc9" + integrity sha512-FXrmSUAN6bSGxDANResNCZQ8VRRLr5bSyy73/HyqSXGdiVuogppGAoRocy7NTVZY4Wc2sWUofmWwwIXE6OxS6Q== + typescript@^5.4.5: version "5.5.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" From 1c03587e24ff9194e07b66b906409360a89c4602 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:57:32 +0900 Subject: [PATCH 02/14] chore: renamed eslint --- eslint.config.js => eslint.config.cjs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename eslint.config.js => eslint.config.cjs (100%) diff --git a/eslint.config.js b/eslint.config.cjs similarity index 100% rename from eslint.config.js rename to eslint.config.cjs From 177848c9c7fd5585d6b79a331e5a277752227174 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 15:21:59 +0900 Subject: [PATCH 03/14] chore: changed config generation --- .github/workflows/update-configuration.yml | 58 ++++++++++++++++++++++ .github/workflows/validate-schema.yml | 38 -------------- src/helpers/validator.ts | 21 ++++++-- src/parser/payload.ts | 8 +-- src/run.ts | 3 +- src/types/context.ts | 4 +- src/types/plugin-inputs.ts | 8 +-- src/validate-schema.ts | 42 ---------------- tests/main.test.ts | 8 +-- 9 files changed, 92 insertions(+), 98 deletions(-) create mode 100644 .github/workflows/update-configuration.yml delete mode 100644 .github/workflows/validate-schema.yml delete mode 100644 src/validate-schema.ts diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml new file mode 100644 index 0000000..f53dbd7 --- /dev/null +++ b/.github/workflows/update-configuration.yml @@ -0,0 +1,58 @@ +name: "Update Configuration" + +on: + workflow_dispatch: + push: + +jobs: + update: + name: "Update Configuration in manifest.json" + runs-on: ubuntu-latest + permissions: write-all + + steps: + - uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: "20.10.0" + + - name: Install deps and run configuration update + run: | + yarn install --immutable --immutable-cache --check-cache + yarn tsc --noCheck --project tsconfig.json + + - name: Update manifest configuration using GitHub Script + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const path = require('path'); + + const { pluginSettingsSchema } = require('./src/types'); + + const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); + const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); + + const configuration = JSON.stringify(pluginSettingsSchema); + + manifest["configuration"] = JSON.parse(configuration); + + const updatedManifest = JSON.stringify(manifest, null, 2) + console.log('Updated manifest:', updatedManifest); + fs.writeFileSync(manifestPath, updatedManifest); + + - name: Commit and Push generated types + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add ./manifest.json + if [ -n "$(git diff-index --cached --name-only HEAD)" ]; then + git commit -m "chore: updated generated configuration" || echo "Lint-staged check failed" + git push origin HEAD:${{ github.ref_name }} + else + echo "No changes to commit" + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml deleted file mode 100644 index 7325b87..0000000 --- a/.github/workflows/validate-schema.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: "Validate Schema" - -on: - workflow_dispatch: - inputs: - stateId: - description: "State Id" - eventName: - description: "Event Name" - eventPayload: - description: "Event Payload" - settings: - description: "Settings" - authToken: - description: "Auth Token" - ref: - description: "Ref" - -jobs: - validate: - name: "Validate Schema" - runs-on: ubuntu-latest - permissions: write-all - - steps: - - uses: actions/checkout@v4 - - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version: "20.10.0" - - - name: Install deps and run validation - run: | - yarn install --immutable --immutable-cache --check-cache - yarn tsx src/validate-schema.ts - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index 9f749c1..eb5d3cb 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -1,5 +1,7 @@ +import * as github from "@actions/github"; +import { Octokit } from "@octokit/rest"; import { TransformDecodeCheckError, TransformDecodeError, Value, ValueError } from "@sinclair/typebox/value"; -import { Env, envSchema, envValidator, pluginSettingsValidator, UserActivityWatcherSettings, userActivityWatcherSettingsSchema } from "../types/plugin-inputs"; +import { Env, envSchema, envValidator, pluginSettingsValidator, PluginSettings, pluginSettingsSchema } from "../types/plugin-inputs"; export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const errors: ValueError[] = []; @@ -12,7 +14,7 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { } } - const settings = Value.Default(userActivityWatcherSettingsSchema, rawSettings) as UserActivityWatcherSettings; + const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings; if (!pluginSettingsValidator.test(settings)) { for (const error of pluginSettingsValidator.errors(settings)) { console.error(error); @@ -25,7 +27,7 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { } try { - const decodedSettings = Value.Decode(userActivityWatcherSettingsSchema, settings); + const decodedSettings = Value.Decode(pluginSettingsSchema, settings); const decodedEnv = Value.Decode(envSchema, rawEnv || {}); return { decodedEnv, decodedSettings }; } catch (e) { @@ -36,3 +38,16 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { throw e; } } + +export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_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), + }, + }); +} diff --git a/src/parser/payload.ts b/src/parser/payload.ts index 19b2150..a715569 100644 --- a/src/parser/payload.ts +++ b/src/parser/payload.ts @@ -1,12 +1,12 @@ import * as github from "@actions/github"; -import { Value } from "@sinclair/typebox/value"; import { config } from "dotenv"; -import { PluginInputs, userActivityWatcherSettingsSchema } from "../types/plugin-inputs"; +import { validateAndDecodeSchemas } from "../helpers/validator"; +import { PluginInputs } from "../types/plugin-inputs"; config(); const webhookPayload = github.context.payload.inputs; -const settings = Value.Decode(userActivityWatcherSettingsSchema, Value.Default(userActivityWatcherSettingsSchema, JSON.parse(webhookPayload.settings))); +const { decodedSettings } = validateAndDecodeSchemas(JSON.parse(webhookPayload.settings), process.env); const program: PluginInputs = { stateId: webhookPayload.stateId, @@ -14,7 +14,7 @@ const program: PluginInputs = { authToken: webhookPayload.authToken, ref: webhookPayload.ref, eventPayload: JSON.parse(webhookPayload.eventPayload), - settings, + settings: decodedSettings, }; export default program; diff --git a/src/run.ts b/src/run.ts index 7c48a1b..d6b263a 100644 --- a/src/run.ts +++ b/src/run.ts @@ -1,4 +1,5 @@ import { Octokit } from "@octokit/rest"; +import { returnDataToKernel } from "./helpers/validator"; import { Context } from "./types/context"; import { PluginInputs } from "./types/plugin-inputs"; import { Logs } from "@ubiquity-dao/ubiquibot-logger"; @@ -14,7 +15,7 @@ export async function run(inputs: PluginInputs) { logger: new Logs("verbose"), }; await runPlugin(context); - return JSON.stringify({ status: 200 }); + return returnDataToKernel(process.env.GITHUB_TOKEN, inputs.stateId, {}); } export async function runPlugin(context: Context) { diff --git a/src/types/context.ts b/src/types/context.ts index 0ff5ce5..cb6fc06 100644 --- a/src/types/context.ts +++ b/src/types/context.ts @@ -1,12 +1,12 @@ import { EmitterWebhookEvent as WebhookEvent, EmitterWebhookEventName as WebhookEventName } from "@octokit/webhooks"; import { Octokit } from "@octokit/rest"; -import { SupportedEvents, UserActivityWatcherSettings } from "./plugin-inputs"; +import { SupportedEvents, PluginSettings } from "./plugin-inputs"; import { Logs } from "@ubiquity-dao/ubiquibot-logger"; export interface Context { eventName: T; payload: WebhookEvent["payload"]; octokit: InstanceType; - config: UserActivityWatcherSettings; + config: PluginSettings; logger: Logs; } diff --git a/src/types/plugin-inputs.ts b/src/types/plugin-inputs.ts index 4586ee1..ed0d727 100644 --- a/src/types/plugin-inputs.ts +++ b/src/types/plugin-inputs.ts @@ -9,7 +9,7 @@ export interface PluginInputs { stateId: string; eventName: T; eventPayload: WebhookEvent["payload"]; - settings: UserActivityWatcherSettings; + settings: PluginSettings; authToken: string; ref: string; } @@ -32,7 +32,7 @@ function thresholdType(options?: StringOptions) { }); } -export const userActivityWatcherSettingsSchema = T.Object({ +export const pluginSettingsSchema = T.Object({ /** * Delay to send reminders. 0 means disabled. Any other value is counted in days, e.g. 1,5 days */ @@ -52,9 +52,9 @@ export const userActivityWatcherSettingsSchema = T.Object({ }), }); -export const pluginSettingsValidator = new StandardValidator(userActivityWatcherSettingsSchema); +export const pluginSettingsValidator = new StandardValidator(pluginSettingsSchema); -export type UserActivityWatcherSettings = StaticDecode; +export type PluginSettings = StaticDecode; export const envSchema = T.Object({}); diff --git a/src/validate-schema.ts b/src/validate-schema.ts deleted file mode 100644 index dfaace2..0000000 --- a/src/validate-schema.ts +++ /dev/null @@ -1,42 +0,0 @@ -import * as core from "@actions/core"; -import * as github from "@actions/github"; -import { Octokit } from "@octokit/rest"; -import { validateAndDecodeSchemas } from "./helpers/validator"; - -export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_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), - }, - }); -} - -async function main() { - const payload = github.context.payload.inputs; - - validateAndDecodeSchemas(process.env, JSON.parse(payload.settings)); - return { errors: [], payload }; -} - -main() - .then((payload) => { - console.log("Configuration validated."); - return payload; - }) - .catch((errors) => { - console.error("Failed to validate configuration", errors); - core.setFailed(errors); - return errors; - }) - .then(async (errors) => { - const payload = github.context.payload.inputs; - await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, errors, "configuration_validation"); - }) - .catch((e) => { - console.error("Failed to return the data to the kernel.", e); - }); diff --git a/tests/main.test.ts b/tests/main.test.ts index 172117a..4f6ade7 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -1,7 +1,7 @@ import { drop } from "@mswjs/data"; import { TransformDecodeError, Value } from "@sinclair/typebox/value"; import { runPlugin } from "../src/run"; -import { userActivityWatcherSettingsSchema } from "../src/types/plugin-inputs"; +import { pluginSettingsSchema } from "../src/types/plugin-inputs"; import { db } from "./__mocks__/db"; import { server } from "./__mocks__/node"; import cfg from "./__mocks__/results/valid-configuration.json"; @@ -32,12 +32,12 @@ describe("User start/stop", () => { }); it("Should parse thresholds", async () => { - const settings = Value.Decode(userActivityWatcherSettingsSchema, Value.Default(userActivityWatcherSettingsSchema, cfg)); + const settings = Value.Decode(pluginSettingsSchema, Value.Default(pluginSettingsSchema, cfg)); expect(settings).toEqual({ warning: 302400000, disqualification: 604800000, watch: { optOut: [STRINGS.PRIVATE_REPO_NAME] } }); expect(() => Value.Decode( - userActivityWatcherSettingsSchema, - Value.Default(userActivityWatcherSettingsSchema, { + pluginSettingsSchema, + Value.Default(pluginSettingsSchema, { warning: "12 foobars", disqualification: "2 days", watch: { optOut: [STRINGS.PRIVATE_REPO_NAME] }, From de1214687bcdc9001525cfa37e9b7c548cc355f1 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 15:25:02 +0900 Subject: [PATCH 04/14] chore: changed config generation --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e56095d..5239250 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "prettier": "3.3.0", "supabase": "1.176.9", "ts-jest": "29.1.4", - "typescript": "^5.4.5" + "typescript": "5.6.2" }, "lint-staged": { "*.ts": [ diff --git a/yarn.lock b/yarn.lock index 152cfff..fd2aa9d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5194,10 +5194,10 @@ typebox-validators@0.3.5: resolved "https://registry.yarnpkg.com/typebox-validators/-/typebox-validators-0.3.5.tgz#b913bad0a87571ffe0edd01d2b6090a268e1ecc9" integrity sha512-FXrmSUAN6bSGxDANResNCZQ8VRRLr5bSyy73/HyqSXGdiVuogppGAoRocy7NTVZY4Wc2sWUofmWwwIXE6OxS6Q== -typescript@^5.4.5: - version "5.5.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" - integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== +typescript@5.6.2: + version "5.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0" + integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw== undici-types@~5.26.4: version "5.26.5" From 9cd1e53eb1570a80682b2f465dadf03650046c51 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 15:29:43 +0900 Subject: [PATCH 05/14] chore: changed config generation --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5239250..45c75be 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "user-activity-watcher", "version": "1.0.0", "description": "Watches user activity on issues, sends reminders on deadlines, and unassign inactive users.", - "main": "src/worker.ts", + "main": "src/index.ts", "author": "Ubiquity DAO", "license": "MIT", "type": "module", From 7626ddb7534452abe584667ee74d7ed1149f8185 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 15:56:07 +0900 Subject: [PATCH 06/14] chore: changed config generation --- .github/workflows/update-configuration.yml | 2 +- tsconfig.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml index f53dbd7..903d116 100644 --- a/.github/workflows/update-configuration.yml +++ b/.github/workflows/update-configuration.yml @@ -30,7 +30,7 @@ jobs: const fs = require('fs'); const path = require('path'); - const { pluginSettingsSchema } = require('./src/types'); + const { pluginSettingsSchema } = require('./src/types/plugin-inputs.js'); const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); diff --git a/tsconfig.json b/tsconfig.json index c6d3097..7f76784 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "target": "ES2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ @@ -25,9 +25,9 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "commonjs" /* Specify what module code is generated. */, + "module": "ESNext" /* Specify what module code is generated. */, // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ From d202b75f90a87f42653598cd29d51400fe5861c8 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 15:58:47 +0900 Subject: [PATCH 07/14] chore: changed config generation --- .github/workflows/update-configuration.yml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml index 903d116..817f07e 100644 --- a/.github/workflows/update-configuration.yml +++ b/.github/workflows/update-configuration.yml @@ -27,21 +27,23 @@ jobs: uses: actions/github-script@v7 with: script: | - const fs = require('fs'); - const path = require('path'); + import { promises as fs } from 'fs'; + import path from 'path'; - const { pluginSettingsSchema } = require('./src/types/plugin-inputs.js'); + import { pluginSettingsSchema } from './dist/types.js'; // Ensure the `.js` extension is included - const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); - const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); + (async () => { + const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); + const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')); - const configuration = JSON.stringify(pluginSettingsSchema); + const configuration = JSON.stringify(pluginSettingsSchema); - manifest["configuration"] = JSON.parse(configuration); + manifest["configuration"] = JSON.parse(configuration); - const updatedManifest = JSON.stringify(manifest, null, 2) - console.log('Updated manifest:', updatedManifest); - fs.writeFileSync(manifestPath, updatedManifest); + const updatedManifest = JSON.stringify(manifest, null, 2); + console.log('Updated manifest:', updatedManifest); + await fs.writeFile(manifestPath, updatedManifest); + })(); - name: Commit and Push generated types run: | From ebacafb6fb6a29736dbaaa0390b843bd3658c058 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 16:11:22 +0900 Subject: [PATCH 08/14] chore: changed config generation --- .github/workflows/update-configuration.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml index 817f07e..0615268 100644 --- a/.github/workflows/update-configuration.yml +++ b/.github/workflows/update-configuration.yml @@ -29,15 +29,13 @@ jobs: script: | import { promises as fs } from 'fs'; import path from 'path'; - - import { pluginSettingsSchema } from './dist/types.js'; // Ensure the `.js` extension is included + import { pluginSettingsSchema } from './src/types/plugin-inputs.js'; (async () => { const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')); const configuration = JSON.stringify(pluginSettingsSchema); - manifest["configuration"] = JSON.parse(configuration); const updatedManifest = JSON.stringify(manifest, null, 2); From 558f8776a5ed5a6deb1041aba15379b1f39918a5 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 16:25:54 +0900 Subject: [PATCH 09/14] chore: changed config generation --- .github/workflows/update-configuration.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml index 0615268..9f31ae2 100644 --- a/.github/workflows/update-configuration.yml +++ b/.github/workflows/update-configuration.yml @@ -27,11 +27,12 @@ jobs: uses: actions/github-script@v7 with: script: | - import { promises as fs } from 'fs'; - import path from 'path'; - import { pluginSettingsSchema } from './src/types/plugin-inputs.js'; - (async () => { + const fs = await import('fs/promises'); + const path = await import('path'); + + const { pluginSettingsSchema } = await import("./src/types/plugin-inputs.js"); + const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')); From 890626c1a4b57ef2615e082f687344a5a6b2c4b6 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 16:27:59 +0900 Subject: [PATCH 10/14] chore: changed config generation --- .github/workflows/update-configuration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml index 9f31ae2..22955a8 100644 --- a/.github/workflows/update-configuration.yml +++ b/.github/workflows/update-configuration.yml @@ -31,7 +31,7 @@ jobs: const fs = await import('fs/promises'); const path = await import('path'); - const { pluginSettingsSchema } = await import("./src/types/plugin-inputs.js"); + const { pluginSettingsSchema } = await import("${{ github.workspace }}/src/types/plugin-inputs.js"); const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')); From 4a29dc5e5ca949855ab4e5ae4ff365ca6485d207 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 2 Oct 2024 07:31:10 +0000 Subject: [PATCH 11/14] chore: updated generated configuration --- manifest.json | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 7731d05..3477e3d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,41 @@ { "name": "User activity watcher", "description": "Watches user activity on issues, sends reminders on deadlines, and unassign inactive users.", - "ubiquity:listeners": ["pull_request_review_comment.created", "issue_comment.created", "push"] -} + "ubiquity:listeners": [ + "pull_request_review_comment.created", + "issue_comment.created", + "push" + ], + "configuration": { + "type": "object", + "properties": { + "warning": { + "default": "3.5 days", + "type": "string" + }, + "watch": { + "type": "object", + "properties": { + "optOut": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "optOut" + ] + }, + "disqualification": { + "default": "7 days", + "type": "string" + } + }, + "required": [ + "warning", + "watch", + "disqualification" + ] + } +} \ No newline at end of file From 6ac650ae24e18450a014c457a4f6513299889106 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 16:32:39 +0900 Subject: [PATCH 12/14] chore: changed config generation --- src/helpers/validator.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index eb5d3cb..92c4ce1 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -9,7 +9,6 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const env = Value.Default(envSchema, rawEnv) as Env; if (!envValidator.test(env)) { for (const error of envValidator.errors(env)) { - console.error(error); errors.push(error); } } @@ -17,7 +16,6 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings; if (!pluginSettingsValidator.test(settings)) { for (const error of pluginSettingsValidator.errors(settings)) { - console.error(error); errors.push(error); } } @@ -31,7 +29,6 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const decodedEnv = Value.Decode(envSchema, rawEnv || {}); return { decodedEnv, decodedSettings }; } catch (e) { - console.error("validateAndDecodeSchemas", e); if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { throw { errors: [e.error] }; } From 75c0cf1d6d25d52f3725c252421d79bf84bb262b Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Thu, 3 Oct 2024 20:40:59 +0900 Subject: [PATCH 13/14] chore: changed git commit username --- .github/workflows/update-configuration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml index 22955a8..ef75268 100644 --- a/.github/workflows/update-configuration.yml +++ b/.github/workflows/update-configuration.yml @@ -46,8 +46,8 @@ jobs: - name: Commit and Push generated types run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git config --global user.name 'ubiquity-os[bot]' + git config --global user.email 'ubiquity-os[bot]@users.noreply.github.com' git add ./manifest.json if [ -n "$(git diff-index --cached --name-only HEAD)" ]; then git commit -m "chore: updated generated configuration" || echo "Lint-staged check failed" From 3182d29895f9c12b8fd7717f28b22cc9ab334567 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Thu, 3 Oct 2024 20:42:23 +0900 Subject: [PATCH 14/14] chore: changed return --- src/helpers/validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index 92c4ce1..feeb043 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -36,7 +36,7 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { } } -export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_kernel") { +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,