refactor: deduplicate listPullRequestFiles into github/pulls.ts (D-02)

This commit is contained in:
wdawdwa committed 2026-08-23 11:20:16 +08:00
1 parent 5a2e902a9e
commit 941e1d2681
4 files changed
+31 -62

No files matched your search

+1 -21
View File
@@ -17,6 +17,7 @@ import {
writeKnowledgeScratch
} from "../repository/knowledge.js";
import { hasProtectedSegment, isProtectedBasename } from "../security/sanitization.js";
import { listPullRequestFiles } from "../github/pulls.js";
const CHAT_MARKER_PREFIX = "<!-- ghbot-chat:v1";
const MAX_REPLY_CHARS = 60_000;
@@ -196,27 +197,6 @@ async function hasExistingReply(
return comments.some((comment) => comment.body?.includes(marker));
}
async function listPullRequestFiles(
octokit: Octokit,
owner: string,
repo: string,
pullNumber: number
): Promise<PullRequestFile[]> {
const files = await octokit.paginate(octokit.rest.pulls.listFiles, {
owner,
repo,
pull_number: pullNumber,
per_page: 100
});
return files.map((file) => ({
filename: file.filename,
patch: file.patch,
status: file.status,
additions: file.additions,
deletions: file.deletions
}));
}
export function chatReplyLanguageInstruction(commentBody: string): string {
const language = /\p{Script=Han}/u.test(commentBody) ? "Chinese" : "English";
+28
View File
@@ -0,0 +1,28 @@
import type { Octokit } from "@octokit/rest";
import type { PullRequestFile } from "../types.js";
/**
* Shared paginated PR file listing used by the review processor, the PR chat
* snapshot flow, and the webhook context loader.
*/
export async function listPullRequestFiles(
octokit: Octokit,
owner: string,
repo: string,
pullNumber: number
): Promise<PullRequestFile[]> {
const files = await octokit.paginate(octokit.rest.pulls.listFiles, {
owner,
repo,
pull_number: pullNumber,
per_page: 100
});
return files.map((file) => ({
filename: file.filename,
patch: file.patch,
status: file.status,
additions: file.additions,
deletions: file.deletions
}));
}
+1 -21
View File
@@ -4,6 +4,7 @@ import { requiredChecksAreGreen } from "../github/checks.js";
import { postPermissionDeniedComment } from "../github/commandFeedback.js";
import { formatBotDisplayName } from "../github/botIdentity.js";
import { collectValidNewLines, toDiffPosition } from "../github/diff.js";
import { listPullRequestFiles } from "../github/pulls.js";
import { logger } from "../logger.js";
import { withRetry } from "../retry.js";
import type { PullRequestFile, PullRequestRef, ReviewDecision, ReviewMode } from "../types.js";
@@ -1103,27 +1104,6 @@ async function getLatestBotReviewOutcomeForHead(
return null;
}
async function listPullRequestFiles(
octokit: Octokit,
owner: string,
repo: string,
pullNumber: number
): Promise<PullRequestFile[]> {
const files = await octokit.paginate(octokit.rest.pulls.listFiles, {
owner,
repo,
pull_number: pullNumber,
per_page: 100
});
return files.map((file) => ({
filename: file.filename,
patch: file.patch,
status: file.status,
additions: file.additions,
deletions: file.deletions
}));
}
async function submitReview(
octokit: Octokit,
+1 -20
View File
@@ -6,6 +6,7 @@ import { logger } from "../logger.js";
import { withRetry } from "../retry.js";
import { compactFilesForReview } from "../review/prompt.js";
import type { PullRequestFile } from "../types.js";
import { listPullRequestFiles } from "../github/pulls.js";
const WEBHOOK_CHAT_MARKER = "<!-- ghbot-webhook-chat:v1";
const MAX_WEBHOOK_REPLY_CHARS = 60_000;
@@ -357,26 +358,6 @@ async function listIssueComments(
}));
}
async function listPullRequestFiles(
octokit: Octokit,
owner: string,
repo: string,
pullNumber: number
): Promise<PullRequestFile[]> {
const files = await octokit.paginate(octokit.rest.pulls.listFiles, {
owner,
repo,
pull_number: pullNumber,
per_page: 100
});
return files.map((file) => ({
filename: file.filename,
patch: file.patch,
status: file.status,
additions: file.additions,
deletions: file.deletions
}));
}
async function loadReadme(octokit: Octokit, owner: string, repo: string): Promise<string> {
try {