Skip to content

Commit

Permalink
chore: camelCase and add config test
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 26, 2024
1 parent c4e98b6 commit 48faffb
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 20 deletions.
1 change: 0 additions & 1 deletion .env.example

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins:
- plugin: http://localhost:4000
with:
# Use your own app name for local testing
ubiquity_os_app_slug: "UbiquityOS"
ubiquityOsAppSlug: "UbiquityOS"
```
`.dev.vars` (for local testing):
Expand Down
4 changes: 0 additions & 4 deletions src/handlers/ask-gpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export async function askGpt(context: Context, formattedChat: string) {
env: { OPENAI_API_KEY },
} = context;

if (!OPENAI_API_KEY) {
throw logger.error(`No OpenAI API Key detected!`);
}

const openAi = new OpenAI({ apiKey: OPENAI_API_KEY });

const chat = createChatHistory(formattedChat);
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export async function plugin(inputs: PluginInputs, env: Env) {
export async function runPlugin(context: Context) {
const {
logger,
config: { ubiquity_os_app_slug },
config: { ubiquityOsAppSlug },
} = context;
const question = context.payload.comment.body;

const slugRegex = new RegExp(`@${ubiquity_os_app_slug} `, "gi");
const slugRegex = new RegExp(`@${ubiquityOsAppSlug} `, "gi");

if (!question.match(slugRegex)) {
logger.info("Comment does not mention the app. Skipping.");
Expand Down
2 changes: 1 addition & 1 deletion src/types/plugin-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface PluginInputs<T extends SupportedEventsU = SupportedEventsU, TU
*/

export const pluginSettingsSchema = T.Object({
ubiquity_os_app_slug: T.String(),
ubiquityOsAppSlug: T.String(),
});

export const pluginSettingsValidator = new StandardValidator(pluginSettingsSchema);
Expand Down
17 changes: 6 additions & 11 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import issueTemplate from "./__mocks__/issue-template";
import repoTemplate from "./__mocks__/repo-template";
import { askQuestion } from "../src/handlers/ask-gpt";
import { runPlugin } from "../src/plugin";
import { TransformDecodeCheckError, Value } from "@sinclair/typebox/value";
import { envSchema } from "../src/types/env";

const TEST_QUESTION = "what is pi?";
const TEST_SLASH_COMMAND = "@UbiquityOS what is pi?";
Expand Down Expand Up @@ -95,16 +97,9 @@ describe("Ask plugin tests", () => {

expect(infoSpy).toHaveBeenCalledWith("Comment is empty. Skipping.");
});

it("should not ask GPT a question if no OpenAI API key is provided", async () => {
const ctx = createContext(TEST_SLASH_COMMAND);
const errorSpy = jest.spyOn(ctx.logger, "error");

createComments([transformCommentTemplate(1, 1, TEST_QUESTION, "ubiquity", "test-repo", true)]);
ctx.env.OPENAI_API_KEY = "";
await runPlugin(ctx);

expect(errorSpy).toHaveBeenNthCalledWith(1, "No OpenAI API Key detected!");
it("Should throw if OPENAI_API_KEY is not defined", () => {
const settings = {};
expect(() => Value.Decode(envSchema, settings)).toThrow(TransformDecodeCheckError);
});

it("should construct the chat history correctly", async () => {
Expand Down Expand Up @@ -305,7 +300,7 @@ function createContext(body = TEST_SLASH_COMMAND) {
},
logger: new Logs("debug"),
config: {
ubiquity_os_app_slug: "UbiquityOS",
ubiquityOsAppSlug: "UbiquityOS",
},
env: {
OPENAI_API_KEY: "test",
Expand Down

0 comments on commit 48faffb

Please sign in to comment.