Skip to content

Commit

Permalink
chore: logger, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Oct 25, 2024
1 parent 8470575 commit 1a2e9bb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
17 changes: 9 additions & 8 deletions src/handlers/comment-created-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ export async function issueCommentCreatedCallback(
env: { UBIQUITY_OS_APP_NAME },
} = context;
const question = context.payload.comment.body.trim();
if (!question || question.length === 0) {
return { status: 204, reason: logger.info("Comment is empty. Skipping.").logMessage.raw };
}
const slugRegex = new RegExp(`@${UBIQUITY_OS_APP_NAME} `, "gi");
if (!question.match(slugRegex)) {
const slugRegex = new RegExp(`@${UBIQUITY_OS_APP_NAME}`, "gi");

if (!slugRegex.test(question)) {
return { status: 204, reason: logger.info("Comment does not mention the app. Skipping.").logMessage.raw };
}

if (!question.length || question.replace(slugRegex, "").trim().length === 0) {
return { status: 204, reason: logger.info("No question provided. Skipping.").logMessage.raw };
}

if (context.payload.comment.user?.type === "Bot") {
return { status: 204, reason: logger.info("Comment is from a bot. Skipping.").logMessage.raw };
}
if (question.replace(slugRegex, "").trim().length === 0) {
return { status: 204, reason: logger.info("Comment is empty. Skipping.").logMessage.raw };
}

logger.info(`Asking question: ${question}`);

try {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogReturn, Logs } from "@ubiquity-dao/ubiquibot-logger";
import { LogReturn, Logs } from "@ubiquity-os/ubiquity-os-logger";
import { Context } from "../types";
import { addCommentToIssue } from "../handlers/add-comment";
export const logger = new Logs("debug");
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Octokit } from "@octokit/rest";
import { PluginInputs } from "./types";
import { Context } from "./types";
import { LogLevel, Logs } from "@ubiquity-dao/ubiquibot-logger";
import { LogLevel, Logs } from "@ubiquity-os/ubiquity-os-logger";
import { Env } from "./types/env";
import { createAdapters } from "./adapters";
import { createClient } from "@supabase/supabase-js";
Expand Down
8 changes: 4 additions & 4 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { db } from "./__mocks__/db";
import { server } from "./__mocks__/node";
import usersGet from "./__mocks__/users-get.json";
import { expect, describe, beforeAll, beforeEach, afterAll, afterEach, it } from "@jest/globals";
import { Logs } from "@ubiquity-dao/ubiquibot-logger";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { Context, SupportedEventsU } from "../src/types";
import { drop } from "@mswjs/data";
import issueTemplate from "./__mocks__/issue-template";
Expand Down Expand Up @@ -93,7 +93,7 @@ describe("Ask plugin tests", () => {
createComments([transformCommentTemplate(1, 1, TEST_QUESTION, "ubiquity", "test-repo", true)]);
await runPlugin(ctx);

expect(infoSpy).toHaveBeenCalledWith("Comment is empty. Skipping.");
expect(infoSpy).toHaveBeenCalledWith("No question provided. Skipping.");
});
it("Should throw if OPENAI_API_KEY is not defined", () => {
const settings = {};
Expand Down Expand Up @@ -168,7 +168,7 @@ describe("Ask plugin tests", () => {
`;

const normalizedExpected = normalizeString(prompt);
const normalizedReceived = normalizeString(infoSpy.mock.calls[1][0]);
const normalizedReceived = normalizeString(infoSpy.mock.calls[1][0] as string);

expect(normalizedReceived).toEqual(normalizedExpected);
});
Expand All @@ -187,7 +187,7 @@ function transformCommentTemplate(commentId: number, issueNumber: number, body:
login: "ubiquity",
type: "User",
},
body: TEST_QUESTION,
body: body,
url: "https://api.github.com/repos/ubiquity/test-repo/issues/comments/1",
html_url: "https://www.github.com/ubiquity/test-repo/issues/1",
owner: "ubiquity",
Expand Down

0 comments on commit 1a2e9bb

Please sign in to comment.