This commit is contained in:
2026-06-01 20:47:26 -05:00
parent 108b8243a9
commit eb7de776e4
5 changed files with 201 additions and 49 deletions
+42 -5
View File
@@ -1,5 +1,10 @@
import { Gitea } from "@go-gitea/sdk.js";
import type { Comment, ChangedFile, PullReview, Reaction } from "@go-gitea/sdk.js";
import type {
Comment,
ChangedFile,
PullReview,
Reaction,
} from "@go-gitea/sdk.js";
import type { PRContext } from "./types.ts";
const client = new Gitea({
@@ -8,6 +13,7 @@ const client = new Gitea({
});
export async function getPRDiff(pr: PRContext): Promise<string> {
console.log(`Fetching PR #${pr.prNumber} diff for ${pr.owner}/${pr.repo}`);
const res = await client.rest.repository.repoDownloadPullDiffOrPatch({
owner: pr.owner,
repo: pr.repo,
@@ -18,6 +24,9 @@ export async function getPRDiff(pr: PRContext): Promise<string> {
}
export async function getPRFiles(pr: PRContext): Promise<ChangedFile[]> {
console.log(
`Fetching PR #${pr.prNumber} changed files for ${pr.owner}/${pr.repo}`,
);
const res = await client.rest.repository.repoGetPullRequestFiles({
owner: pr.owner,
repo: pr.repo,
@@ -26,7 +35,13 @@ export async function getPRFiles(pr: PRContext): Promise<ChangedFile[]> {
return res.data;
}
export async function postReviewComment(pr: PRContext, body: string): Promise<Comment> {
export async function postReviewComment(
pr: PRContext,
body: string,
): Promise<Comment> {
console.log(
`Posting review comment on PR #${pr.prNumber} for ${pr.owner}/${pr.repo}`,
);
const res = await client.rest.issue.issueCreateComment({
owner: pr.owner,
repo: pr.repo,
@@ -42,6 +57,9 @@ export async function postInlineComment(
line: number,
body: string,
): Promise<PullReview> {
console.log(
`Posting inline review comment on PR #${pr.prNumber} for ${pr.owner}/${pr.repo} at ${file}:${line}`,
);
const res = await client.rest.repository.repoCreatePullReview({
owner: pr.owner,
repo: pr.repo,
@@ -83,6 +101,7 @@ export async function removeReaction(
}
export async function getPR(owner: string, repo: string, prNumber: number) {
console.log(`Fetching PR #${prNumber} data for ${owner}/${repo}`);
const res = await client.rest.repository.repoGetPullRequest({
owner,
repo,
@@ -91,7 +110,13 @@ export async function getPR(owner: string, repo: string, prNumber: number) {
return res.data;
}
export async function getFileContents(pr: PRContext, filePath: string): Promise<string> {
export async function getFileContents(
pr: PRContext,
filePath: string,
): Promise<string> {
console.log(
`Fetching contents of ${filePath} at PR #${pr.prNumber} head for ${pr.owner}/${pr.repo}`,
);
const res = await client.rest.repository.repoGetContents({
owner: pr.owner,
repo: pr.repo,
@@ -104,7 +129,13 @@ export async function getFileContents(pr: PRContext, filePath: string): Promise<
return Buffer.from(entry.content, "base64").toString("utf8");
}
export async function listDir(pr: PRContext, dirPath: string): Promise<string[]> {
export async function listDir(
pr: PRContext,
dirPath: string,
): Promise<string[]> {
console.log(
`Listing directory ${dirPath} at PR #${pr.prNumber} head for ${pr.owner}/${pr.repo}`,
);
const res = await client.rest.repository.repoGetContents({
owner: pr.owner,
repo: pr.repo,
@@ -117,7 +148,13 @@ export async function listDir(pr: PRContext, dirPath: string): Promise<string[]>
// Gitea REST API v1 has no code search endpoint — returns repo names matching the query.
// mcp.ts should strongly prefer disk grep (find_symbol) when workspace is available.
export async function searchCode(pr: PRContext, query: string): Promise<string[]> {
export async function searchCode(
pr: PRContext,
query: string,
): Promise<string[]> {
console.log(
`Searching code for "${query}" at PR #${pr.prNumber} head for ${pr.owner}/${pr.repo}`,
);
const res = await client.rest.repository.repoSearch({
q: query,
limit: 20,