Skip to content

Commit

Permalink
fix: rollback pr review comment support
Browse files Browse the repository at this point in the history
  • Loading branch information
shiv810 committed Jan 23, 2025
1 parent 103ffb8 commit b1c17a9
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 31 deletions.
6 changes: 1 addition & 5 deletions src/handlers/add-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export async function addCommentToIssue(context: Context, message: string, optio
if (options?.inReplyTo) {
let pullNumber: number | undefined;

if ("pull_request" in payload) {
pullNumber = payload.pull_request.number;
} else if ("issue" in payload && payload.issue.pull_request) {
if ("issue" in payload && payload.issue.pull_request) {
pullNumber = payload.issue.number;
} else {
pullNumber = undefined;
Expand All @@ -49,8 +47,6 @@ export async function addCommentToIssue(context: Context, message: string, optio
let issueNumber: number | undefined;
if ("issue" in payload) {
issueNumber = payload.issue.number;
} else if ("pull_request" in payload) {
issueNumber = payload.pull_request.number;
} else {
issueNumber = undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/comment-created-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CallbackResult } from "../types/proxy";
import { bubbleUpErrorComment, sanitizeMetadata } from "../helpers/errors";
import { LogReturn } from "@ubiquity-os/ubiquity-os-logger";

export async function processCommentCallback(context: Context<"issue_comment.created" | "pull_request_review_comment.created">): Promise<CallbackResult> {
export async function processCommentCallback(context: Context<"issue_comment.created">): Promise<CallbackResult> {
const { logger, command, payload } = context;
let question = "";

Expand Down
1 change: 0 additions & 1 deletion src/helpers/callback-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { bubbleUpErrorComment } from "./errors";
*/
const callbacks = {
"issue_comment.created": [processCommentCallback],
"pull_request_review_comment.created": [processCommentCallback],
} as ProxyCallbacks;

export async function callCallbacks<T extends SupportedEvents>(context: Context<T>, eventName: T): Promise<CallbackResult> {
Expand Down
11 changes: 0 additions & 11 deletions src/helpers/format-chat-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ async function buildTree(
let issueNumber;
if ("issue" in context.payload) {
issueNumber = context.payload.issue.number;
} else if ("pull_request" in context.payload) {
issueNumber = context.payload.pull_request.number;
} else {
issueNumber = undefined;
}
Expand Down Expand Up @@ -508,15 +506,6 @@ export async function buildChatHistoryTree(
const specAndBodies: Record<string, string> = {};
const tokenLimits = createDefaultTokenLimits(context);
const { tree } = await buildTree(context, specAndBodies, maxDepth, tokenLimits, similarIssues, similarComments);

if (tree && "pull_request" in context.payload) {
const { diff_hunk, position, original_position, path, body } = context.payload.comment || {};
if (diff_hunk) {
tree.body += `\nPrimary Context: ${body || ""}\nDiff: ${diff_hunk}\nPath: ${path || ""}\nLines: ${position || ""}-${original_position || ""}`;
tree.comments = tree.comments?.filter((comment) => comment.id !== String(context.payload.comment?.id));
}
}

return { tree, tokenLimits };
}

Expand Down
16 changes: 4 additions & 12 deletions src/helpers/issue-fetching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ export async function fetchIssue(params: FetchParams, tokenLimits?: TokenLimits)
const targetRepo = repo || payload.repository.name;
// Handle both issue comments and PR review comments
let targetIssueNum = issueNum;
if (!targetIssueNum && payload.action === "created") {
if ("issue" in payload) {
targetIssueNum = payload.issue.number;
} else if ("pull_request" in payload) {
targetIssueNum = payload.pull_request.number;
}
if (!targetIssueNum && "issue" in payload && payload.action === "created") {
targetIssueNum = payload.issue.number;
}

if (!targetIssueNum) {
Expand Down Expand Up @@ -315,12 +311,8 @@ export async function fetchIssueComments(params: FetchParams, tokenLimits?: Toke
const targetRepo = repo || payload.repository.name;
// Handle both issue comments and PR review comments
let targetIssueNum = issueNum;
if (!targetIssueNum && payload.action === "created") {
if ("issue" in payload) {
targetIssueNum = payload.issue.number;
} else if ("pull_request" in payload) {
targetIssueNum = payload.pull_request.number;
}
if (!targetIssueNum && "issue" in payload && payload.action === "created") {
targetIssueNum = payload.issue.number;
}

if (!targetIssueNum) {
Expand Down
2 changes: 1 addition & 1 deletion src/types/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Env } from "./env";
import { createAdapters } from "../adapters";
import { Command } from "./command";

export type SupportedEvents = "issue_comment.created" | "pull_request_review_comment.created";
export type SupportedEvents = "issue_comment.created";

export type Context<TEvents extends SupportedEvents = SupportedEvents> = PluginContext<PluginSettings, Env, Command, TEvents> & {
adapters: ReturnType<typeof createAdapters>;
Expand Down

0 comments on commit b1c17a9

Please sign in to comment.