Skip to content

Commit

Permalink
Merge pull request #32 from ubiquity-os-marketplace/development
Browse files Browse the repository at this point in the history
Merge development into main
  • Loading branch information
gentlementlegen authored Jan 8, 2025
2 parents 07445f6 + 21a8cf0 commit 043cfeb
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "**/*.http", "**/*.toml", "src/types/database.ts", "dist/**"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir", "typebox", "supabase", "ubiquibot", "mswjs"],
"words": ["dataurl", "devpool", "outdir", "servedir", "typebox", "supabase", "ubiquibot", "mswjs", "sonarjs"],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"]
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/update-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ jobs:

steps:
- uses: ubiquity-os/action-deploy-plugin@main
env:
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/worker-delete.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Delete Deployment
name: Delete Worker

on:
delete:
Expand Down
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn commitlint --edit "$1"
commitlint --edit "$1"
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
lint-staged
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
}
}
},
"homepage_url": "https://ubiquity-os-command-query-user-main.ubiquity.workers.dev"
"homepage_url": "https://ubiquity-os-command-query-user-development.ubiquity.workers.dev"
}
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"prepare": "husky install",
"supabase:generate:local": "supabase gen types typescript --local > src/types/database.ts",
"supabase:generate:remote": "cross-env-shell \"supabase gen types typescript --project-id $SUPABASE_PROJECT_ID --schema public > src/types/database.ts\"",
"test": "jest --setupFiles dotenv/config --coverage"
"test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --setupFiles dotenv/config --coverage"
},
"keywords": [
"typescript",
Expand All @@ -33,7 +33,7 @@
"@octokit/rest": "^20.1.0",
"@sinclair/typebox": "0.34.3",
"@supabase/supabase-js": "2.43.2",
"@ubiquity-os/plugin-sdk": "^1.1.0",
"@ubiquity-os/plugin-sdk": "^2.0.1",
"@ubiquity-os/ubiquity-os-logger": "^1.3.2",
"commander": "12.1.0",
"hono": "^4.6.4"
Expand All @@ -49,17 +49,17 @@
"@mswjs/data": "0.16.1",
"@types/jest": "29.5.12",
"@types/node": "^20.11.19",
"@typescript-eslint/eslint-plugin": "^8.14.0",
"@typescript-eslint/parser": "^8.14.0",
"@typescript-eslint/eslint-plugin": "^8.19.0",
"@typescript-eslint/parser": "^8.19.0",
"cross-env": "7.0.3",
"cspell": "^8.4.0",
"dotenv": "16.4.5",
"dotenv-cli": "7.4.2",
"eslint": "9.14.0",
"eslint": "9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-check-file": "^2.8.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-sonarjs": "^1.0.3",
"eslint-plugin-sonarjs": "^3.0.1",
"husky": "^9.0.11",
"jest": "29.7.0",
"jest-junit": "16.0.0",
Expand All @@ -72,12 +72,12 @@
"ts-jest": "29.1.2",
"ts-node": "^10.9.2",
"typescript": "5.6.2",
"typescript-eslint": "^8.14.0",
"wrangler": "^3.87.0"
"typescript-eslint": "^8.19.0",
"wrangler": "^3.99.0"
},
"lint-staged": {
"*.ts": [
"yarn prettier --write",
"prettier --write",
"eslint --fix"
],
"src/**.{ts,json}": [
Expand All @@ -88,6 +88,5 @@
"extends": [
"@commitlint/config-conventional"
]
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
}
9 changes: 2 additions & 7 deletions src/handlers/query-user.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { postComment } from "@ubiquity-os/plugin-sdk";
import { Context } from "../types/context";

async function checkUserAccess(context: Context, username: string) {
Expand All @@ -23,7 +24,6 @@ async function checkUserAccess(context: Context, username: string) {
export async function queryUser(context: Context, username: string) {
const {
octokit,
payload,
adapters: { supabase },
config,
} = context;
Expand Down Expand Up @@ -54,12 +54,7 @@ User information for ${username} was not found.
body.push(`| Access | \`\`\`${Array.isArray(access.labels) ? access.labels.join(", ") : JSON.stringify(access.labels, null, 2)}\`\`\` |`);
}
}
await octokit.rest.issues.createComment({
body: body.join("\n"),
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
});
await postComment(context, context.logger.info(body.join("\n")), { raw: true, updateComment: true });
} catch (e) {
throw context.logger.fatal(`Could not query user ${username}.`, { e });
}
Expand Down
19 changes: 10 additions & 9 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { postComment } from "@ubiquity-os/plugin-sdk";
import { CommanderError } from "commander";
import { CommandParser } from "./handlers/command-parser";
import { Context } from "./types/context";
import { queryUser } from "./handlers/query-user";

export async function run(context: Context) {
const { octokit, logger, eventName, payload, command } = context;
const { logger, eventName, payload, command } = context;
if (command) {
await queryUser(context, command.parameters.username);
return;
Expand All @@ -20,21 +21,21 @@ export async function run(context: Context) {
} catch (e) {
if (e instanceof CommanderError) {
if (e.code !== "commander.unknownCommand") {
context.logger.fatal("Commander error", { e });
await octokit.rest.issues.createComment({
body: `\`\`\`
await postComment(
context,
context.logger.error(
`\`\`\`
Failed to run command-query-user.
${e.message}
${commandParser.helpInformation()}
\`\`\``,
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.issue.number,
});
{ e }
)
);
}
} else {
context.logger.error("error", { e });
context.logger.fatal("error", { e });
throw e;
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, jest } from "@jest/globals";
import { drop } from "@mswjs/data";
import { Octokit } from "@octokit/rest";
import { createClient } from "@supabase/supabase-js";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { createAdapters } from "../src/adapters";
import { run } from "../src/run";
Expand All @@ -16,14 +15,15 @@ beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

jest.mock("@supabase/supabase-js", () => {
jest.unstable_mockModule("@supabase/supabase-js", () => {
return {
createClient: jest.fn(() => {
return {
from: jest.fn((table: string) => {
return {
select: jest.fn(() => {
return {
// eslint-disable-next-line sonarjs/no-nested-functions
eq: jest.fn(() => {
return {
single: jest.fn(() => {
Expand Down Expand Up @@ -82,6 +82,7 @@ describe("User tests", () => {
},
octokit: new Octokit(),
} as unknown as Context;
const { createClient } = await import("@supabase/supabase-js");
context.adapters = createAdapters(createClient<Database>(context.env.SUPABASE_URL, context.env.SUPABASE_KEY), context);
await expect(run(context)).resolves.not.toThrow();
});
Expand Down

0 comments on commit 043cfeb

Please sign in to comment.