Skip to content

Commit

Permalink
fix: the messages are displayed on catch errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Sep 4, 2024
1 parent ebf98c4 commit c79b63f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 35 deletions.
30 changes: 0 additions & 30 deletions src/handlers/proxy.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/handlers/result-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export enum HttpStatusCode {
OK = 200,
NOT_MODIFIED = 304,
}

export interface Result {
status: HttpStatusCode;
content?: string;
reason?: string;
}
2 changes: 1 addition & 1 deletion src/handlers/shared/start.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, ISSUE_TYPE, Label } from "../../types";
import { addAssignees, addCommentToIssue, getAssignedIssues, getAvailableOpenedPullRequests, getTimeValue, isParentIssue } from "../../utils/issue";
import { HttpStatusCode, Result } from "../proxy";
import { HttpStatusCode, Result } from "../result-types";
import { hasUserBeenUnassigned } from "./check-assignments";
import { checkTaskStale } from "./check-task-stale";
import { generateAssignmentComment, getDeadline } from "./generate-assignment-comment";
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/shared/stop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Assignee, Context, Sender } from "../../types";
import { addCommentToIssue, closePullRequestForAnIssue } from "../../utils/issue";
import { HttpStatusCode, Result } from "../proxy";
import { HttpStatusCode, Result } from "../result-types";

export async function stop(context: Context, issue: Context["payload"]["issue"], sender: Sender, repo: Context["payload"]["repository"]): Promise<Result> {
const { logger } = context;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/user-start-stop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, isContextCommentCreated } from "../types";
import { addCommentToIssue } from "../utils/issue";
import { HttpStatusCode, Result } from "./proxy";
import { HttpStatusCode, Result } from "./result-types";
import { getDeadline } from "./shared/generate-assignment-comment";
import { start } from "./shared/start";
import { stop } from "./shared/stop";
Expand Down
11 changes: 9 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Octokit } from "@octokit/rest";
import { createClient } from "@supabase/supabase-js";
import { LogReturn, Logs } from "@ubiquity-dao/ubiquibot-logger";
import { createAdapters } from "./adapters";
import { proxyCallbacks } from "./handlers/proxy";
import { userSelfAssign, userStartStop } from "./handlers/user-start-stop";
import { Context, Env, PluginInputs } from "./types";
import { addCommentToIssue } from "./utils/issue";

Expand All @@ -23,7 +23,14 @@ export async function startStopTask(inputs: PluginInputs, env: Env) {
context.adapters = createAdapters(supabase, context);

try {
return proxyCallbacks(context)[inputs.eventName](context, env);
switch (context.eventName) {
case "issue_comment.created":
return await userStartStop(context);
case "issues.assigned":
return await userSelfAssign(context);
default:
context.logger.error(`Unsupported event: ${context.eventName}`);
}
} catch (err) {
let errorMessage;
if (err instanceof LogReturn) {
Expand Down

0 comments on commit c79b63f

Please sign in to comment.