From b1c17a9ab5b3abfb257e74f3a6f1c4800f656c6b Mon Sep 17 00:00:00 2001 From: sshivaditya2019 Date: Wed, 22 Jan 2025 21:58:12 -0500 Subject: [PATCH] fix: rollback pr review comment support --- src/handlers/add-comment.ts | 6 +----- src/handlers/comment-created-callback.ts | 2 +- src/helpers/callback-proxy.ts | 1 - src/helpers/format-chat-history.ts | 11 ----------- src/helpers/issue-fetching.ts | 16 ++++------------ src/types/context.ts | 2 +- 6 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/handlers/add-comment.ts b/src/handlers/add-comment.ts index a8db2dc..bbc74e6 100644 --- a/src/handlers/add-comment.ts +++ b/src/handlers/add-comment.ts @@ -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; @@ -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; } diff --git a/src/handlers/comment-created-callback.ts b/src/handlers/comment-created-callback.ts index c5b3816..00903ed 100644 --- a/src/handlers/comment-created-callback.ts +++ b/src/handlers/comment-created-callback.ts @@ -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 { +export async function processCommentCallback(context: Context<"issue_comment.created">): Promise { const { logger, command, payload } = context; let question = ""; diff --git a/src/helpers/callback-proxy.ts b/src/helpers/callback-proxy.ts index 2733206..b8b62de 100644 --- a/src/helpers/callback-proxy.ts +++ b/src/helpers/callback-proxy.ts @@ -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(context: Context, eventName: T): Promise { diff --git a/src/helpers/format-chat-history.ts b/src/helpers/format-chat-history.ts index b9b491c..4d5d4a9 100644 --- a/src/helpers/format-chat-history.ts +++ b/src/helpers/format-chat-history.ts @@ -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; } @@ -508,15 +506,6 @@ export async function buildChatHistoryTree( const specAndBodies: Record = {}; 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 }; } diff --git a/src/helpers/issue-fetching.ts b/src/helpers/issue-fetching.ts index fde4b75..457f7f3 100644 --- a/src/helpers/issue-fetching.ts +++ b/src/helpers/issue-fetching.ts @@ -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) { @@ -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) { diff --git a/src/types/context.ts b/src/types/context.ts index fc06ef0..128b441 100644 --- a/src/types/context.ts +++ b/src/types/context.ts @@ -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 = PluginContext & { adapters: ReturnType;