Skip to content

Commit

Permalink
Merge pull request #198 from ubiquity-whilefoo/command-interface
Browse files Browse the repository at this point in the history
Command interface
  • Loading branch information
gentlementlegen authored Nov 25, 2024
2 parents 73c9ca3 + f3bec94 commit ac3b1da
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ on:
description: "Ref"
signature:
description: "Payload signature from the kernel"
command:
description: "Command"

jobs:
compute:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ static/dist
junit.xml
coverage
test-dashboard.md
*.private.env.json
*.private.env.json
output.html
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default tsEslint.config({
"@typescript-eslint": tsEslint.plugin,
"check-file": checkFile,
},
ignores: [".github/knip.ts", "dist/", "tests/__mocks__/**", "coverage/**"],
ignores: [".github/knip.ts", "dist/", "tests/__mocks__/**", "coverage/**", "dist/**"],
extends: [eslint.configs.recommended, ...tsEslint.configs.recommended, sonarjs.configs.recommended],
languageOptions: {
parser: tsEslint.parser,
Expand Down
2 changes: 1 addition & 1 deletion knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config: KnipConfig = {
project: ["src/**/*.ts"],
ignore: ["src/data-collection/examples/*.ts", "src/configuration/common-config-type.ts", "dist/**"],
ignoreExportsUsedInFile: true,
ignoreDependencies: ["ts-node", "msw", "@mswjs/data", "@octokit/plugin-paginate-graphql"],
ignoreDependencies: ["ts-node", "msw", "@mswjs/data"],
jest: {
config: ["jest.config.ts"],
entry: ["src/**/*.test.ts"],
Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"type": "module",
"scripts": {
"test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --setupFiles dotenv/config --coverage",
"start": "tsx src/index.ts",
"format": "run-s format:lint format:prettier format:cspell",
"format:lint": "eslint --fix .",
"format:prettier": "prettier --write .",
Expand All @@ -31,22 +30,19 @@
"@actions/github": "^6.0.0",
"@octokit/graphql-schema": "^15.25.0",
"@octokit/rest": "^21.0.2",
"@sinclair/typebox": "^0.33.21",
"@sinclair/typebox": "0.34.3",
"@supabase/supabase-js": "2.42.0",
"@ubiquity-dao/rpc-handler": "1.3.0",
"@ubiquity-os/permit-generation": "^2.0.6",
"@ubiquity-os/plugin-sdk": "^1.0.11",
"@ubiquity-os/plugin-sdk": "^1.1.0",
"@ubiquity-os/ubiquity-os-logger": "^1.3.2",
"@octokit/plugin-paginate-graphql": "^5.2.4",
"decimal.js": "10.4.3",
"ethers": "^5.7.2",
"js-tiktoken": "1.0.15",
"jsdom": "24.0.0",
"markdown-it": "14.1.0",
"openai": "4.56.0",
"ts-jest": "^29.2.5",
"tsx": "4.7.1",
"yaml": "^2.6.0"
"yaml": "^2.6.1"
},
"devDependencies": {
"@babel/core": "7.23.9",
Expand Down Expand Up @@ -83,6 +79,7 @@
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7",
"ts-node": "10.9.2",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3",
"typescript-eslint": "^8.13.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { run } from "./run";
import envConfigSchema, { EnvConfig } from "./types/env-type";
import { PluginSettings, pluginSettingsSchema, SupportedEvents } from "./types/plugin-input";

export default createActionsPlugin<PluginSettings, EnvConfig, SupportedEvents>(
export default createActionsPlugin<PluginSettings, EnvConfig, null, SupportedEvents>(
(context) => {
return run(context);
},
Expand Down
2 changes: 1 addition & 1 deletion src/types/plugin-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ export const pluginSettingsSchema = T.Object(
export type PluginSettings = StaticDecode<typeof pluginSettingsSchema>;

export type SupportedEvents = "issues.closed";
export type ContextPlugin = Context<PluginSettings, EnvConfig, SupportedEvents>;
export type ContextPlugin = Context<PluginSettings, EnvConfig, null, SupportedEvents>;
14 changes: 4 additions & 10 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { ContextPlugin } from "../src/types/plugin-input";
import { server } from "./__mocks__/node";
import cfg from "./__mocks__/results/valid-configuration.json";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { Octokit } from "@octokit/rest";
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
import { customOctokit as Octokit } from "@ubiquity-os/plugin-sdk/octokit";

beforeAll(() => server.listen());
beforeEach(() => {
Expand Down Expand Up @@ -57,10 +56,7 @@ describe("Action tests", () => {
const { run } = await import("../src/run");
await expect(
run({
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: "https://github.com/ubiquity-os/comment-incentives/issues/22",
Expand All @@ -76,7 +72,7 @@ describe("Action tests", () => {
},
config: cfg,
logger: new Logs("debug"),
octokit: new (Octokit.plugin(paginateGraphQL).defaults({ auth: process.env.GITHUB_TOKEN }))(),
octokit: new Octokit({ auth: process.env.GITHUB_TOKEN }),
} as unknown as ContextPlugin)
).resolves.toEqual("Issue was not closed as completed. Skipping.");
});
Expand All @@ -93,10 +89,7 @@ describe("Action tests", () => {
const { run } = await import("../src/run");
await expect(
run({
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: "https://github.com/ubiquity-os/comment-incentives/issues/22",
Expand All @@ -112,7 +105,8 @@ describe("Action tests", () => {
},
config: cfg,
logger: new Logs("debug"),
octokit: new (Octokit.plugin(paginateGraphQL).defaults({ auth: process.env.GITHUB_TOKEN }))(),
octokit: new Octokit({ auth: process.env.GITHUB_TOKEN }),
command: null,
} as unknown as ContextPlugin)
).rejects.toEqual({
logMessage: {
Expand Down
3 changes: 0 additions & 3 deletions tests/fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ describe("GithubCommentModule Fee Tests", () => {
beforeEach(async () => {
const { GithubCommentModule } = await import("../src/parser/github-comment-module");
githubCommentModule = new GithubCommentModule({
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: issueUrl,
Expand Down
10 changes: 2 additions & 8 deletions tests/get-activity.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { beforeAll, describe, expect, it, jest } from "@jest/globals";
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
import { Octokit } from "@octokit/rest";
import { customOctokit as Octokit } from "@ubiquity-os/plugin-sdk/octokit";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { IssueActivity } from "../src/issue-activity";
import { parseGitHubUrl } from "../src/start";
Expand All @@ -14,19 +13,14 @@ jest.unstable_mockModule("../src/helpers/get-comment-details", () => ({
getMinimizedCommentStatus: jest.fn(),
}));

const customOctokit = Octokit.plugin(paginateGraphQL).defaults({ auth: process.env.GITHUB_TOKEN });

describe("GetActivity class", () => {
const issue = parseGitHubUrl(issueUrl);
const activity = new IssueActivity(
{
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
config: cfg,
logger: new Logs("debug"),
octokit: new customOctokit(),
octokit: new Octokit({ auth: process.env.GITHUB_TOKEN }),
} as unknown as ContextPlugin,
issue
);
Expand Down
8 changes: 2 additions & 6 deletions tests/parser/permit-generation-module.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { drop } from "@mswjs/data";
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
import { Octokit } from "@octokit/rest";
import { customOctokit as Octokit } from "@ubiquity-os/plugin-sdk/octokit";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { CommentKind } from "../../src/configuration/comment-types";
import { EnvConfig } from "../../src/types/env-type";
Expand All @@ -16,10 +15,7 @@ const DOLLAR_ADDRESS = "0xb6919Ef2ee4aFC163BC954C5678e2BB570c2D103";
const WXDAI_ADDRESS = "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d";

const ctx = {
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: "https://github.com/ubiquity-os/comment-incentives/issues/22",
Expand All @@ -35,7 +31,7 @@ const ctx = {
},
config: cfg,
logger: new Logs("debug"),
octokit: new (Octokit.plugin(paginateGraphQL).defaults({ auth: process.env.GITHUB_TOKEN }))(),
octokit: new Octokit({ auth: process.env.GITHUB_TOKEN }),
env: {
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
SUPABASE_KEY: process.env.SUPABASE_KEY,
Expand Down
8 changes: 2 additions & 6 deletions tests/pre-check.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { drop } from "@mswjs/data";
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
import { Octokit } from "@octokit/rest";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { http, HttpResponse } from "msw";
import { ContextPlugin } from "../src/types/plugin-input";
import { db } from "./__mocks__/db";
import dbSeed from "./__mocks__/db-seed.json";
import { server } from "./__mocks__/node";
import cfg from "./__mocks__/results/valid-configuration.json";
import { customOctokit as Octokit } from "@ubiquity-os/plugin-sdk/octokit";

const issueUrl = "https://github.com/ubiquity/work.ubq.fi/issues/69";

Expand Down Expand Up @@ -82,10 +81,7 @@ describe("Pre-check tests", () => {
server.use(http.patch("https://api.github.com/repos/ubiquity/work.ubq.fi/issues/69", patchMock, { once: true }));
const { run } = await import("../src/run");
const result = await run({
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: issueUrl,
Expand All @@ -102,7 +98,7 @@ describe("Pre-check tests", () => {
},
config: cfg,
logger: new Logs("debug"),
octokit: new (Octokit.plugin(paginateGraphQL).defaults({ auth: process.env.GITHUB_TOKEN }))(),
octokit: new Octokit({ auth: process.env.GITHUB_TOKEN }),
} as unknown as ContextPlugin);
expect(result).toEqual("All linked pull requests must be closed to generate rewards.");
expect(patchMock).toHaveBeenCalled();
Expand Down
8 changes: 2 additions & 6 deletions tests/price-label.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { afterAll, afterEach, beforeAll, expect, it, jest } from "@jest/globals"
import cfg from "./__mocks__/results/valid-configuration.json";
import { ContextPlugin } from "../src/types/plugin-input";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { Octokit } from "@octokit/rest";

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
Expand Down Expand Up @@ -39,16 +38,13 @@ jest.unstable_mockModule("@octokit/plugin-paginate-graphql", () => ({
},
}));

const { paginateGraphQL } = await import("@octokit/plugin-paginate-graphql");
const octokit = (await import("@ubiquity-os/plugin-sdk/octokit")).customOctokit;

describe("Price tests", () => {
it("Should skip when no price label is set", async () => {
const { run } = await import("../src/run");
const result = await run({
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: "https://github.com/ubiquity-os/comment-incentives/issues/22",
Expand All @@ -64,7 +60,7 @@ describe("Price tests", () => {
},
config: cfg,
logger: new Logs("debug"),
octokit: new (Octokit.plugin(paginateGraphQL).defaults({ auth: process.env.GITHUB_TOKEN }))(),
octokit: new octokit({ auth: process.env.GITHUB_TOKEN }),
} as unknown as ContextPlugin);
expect(result).toEqual("No price label has been set. Skipping permit generation.");
});
Expand Down
8 changes: 2 additions & 6 deletions tests/process.issue.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable sonarjs/no-nested-functions */

import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
import { Octokit } from "@octokit/rest";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import fs from "fs";
import { http, passthrough } from "msw";
Expand All @@ -20,6 +18,7 @@ import githubCommentAltResults from "./__mocks__/results/github-comment-zero-res
import permitGenerationResults from "./__mocks__/results/permit-generation-results.json";
import userCommentResults from "./__mocks__/results/user-comment-results.json";
import cfg from "./__mocks__/results/valid-configuration.json";
import { customOctokit as Octokit } from "@ubiquity-os/plugin-sdk/octokit";

const issueUrl = process.env.TEST_ISSUE_URL ?? "https://github.com/ubiquity-os/conversation-rewards/issues/5";

Expand All @@ -46,10 +45,7 @@ jest.unstable_mockModule("../src/helpers/get-comment-details", () => ({
}));

const ctx = {
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: "https://github.com/ubiquity-os/conversation-rewards/issues/5",
Expand All @@ -66,7 +62,7 @@ const ctx = {
},
config: cfg,
logger: new Logs("debug"),
octokit: new (Octokit.plugin(paginateGraphQL).defaults({ auth: process.env.GITHUB_TOKEN }))(),
octokit: new Octokit({ auth: process.env.GITHUB_TOKEN }),
env: {
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
SUPABASE_KEY: process.env.SUPABASE_KEY,
Expand Down
8 changes: 2 additions & 6 deletions tests/purging.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { drop } from "@mswjs/data";
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
import { Octokit } from "@octokit/rest";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { GitHubIssueComment } from "../src/github-types";
import { ContentEvaluatorModule } from "../src/parser/content-evaluator-module";
Expand All @@ -15,6 +13,7 @@ import dbSeed from "./__mocks__/db-seed.json";
import { server } from "./__mocks__/node";
import hiddenCommentPurged from "./__mocks__/results/hidden-comment-purged.json";
import cfg from "./__mocks__/results/valid-configuration.json";
import { customOctokit as Octokit } from "@ubiquity-os/plugin-sdk/octokit";

const issueUrl = "https://github.com/Meniole/conversation-rewards/issues/13";

Expand Down Expand Up @@ -46,10 +45,7 @@ jest.unstable_mockModule("../src/data-collection/collect-linked-pulls", () => ({
}));

const ctx = {
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: issueUrl,
Expand All @@ -66,7 +62,7 @@ const ctx = {
},
config: cfg,
logger: new Logs("debug"),
octokit: new (Octokit.plugin(paginateGraphQL).defaults({ auth: process.env.GITHUB_TOKEN }))(),
octokit: new Octokit({ auth: process.env.GITHUB_TOKEN }),
env: {
OPENAI_API_KEY: "1234",
SUPABASE_URL: "http://localhost:8080",
Expand Down
5 changes: 1 addition & 4 deletions tests/rewards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { afterAll, afterEach, beforeAll, beforeEach, describe, it, jest } from "@jest/globals";
import { drop } from "@mswjs/data";
import { Octokit } from "@octokit/rest";
import { customOctokit as Octokit } from "@ubiquity-os/plugin-sdk/octokit";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import fs from "fs";
import { http, passthrough } from "msw";
Expand Down Expand Up @@ -148,10 +148,7 @@ jest
describe("Rewards tests", () => {
const issue = parseGitHubUrl(issueUrl);
const ctx = {
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: issueUrl,
Expand Down
3 changes: 0 additions & 3 deletions tests/truncate-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ describe("Payload truncate tests", () => {
});
const module = await import("../src/run");
const result = await module.run({
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
payload: {
issue: {
html_url: issueUrl,
Expand Down

0 comments on commit ac3b1da

Please sign in to comment.