fix: issues with pagination not resolving correct url templates
This commit is contained in:
@@ -6,16 +6,10 @@ import { $ } from "../utils/shell.ts";
|
||||
import type { ToolContext } from "./server.ts";
|
||||
import { execute, tool } from "./shared.ts";
|
||||
|
||||
export const PullRequest = type({
|
||||
title: type.string.describe("the title of the pull request"),
|
||||
body: type.string.describe("the body content of the pull request"),
|
||||
base: type.string.describe("the base branch to merge into (e.g., 'main')"),
|
||||
"draft?": type.boolean.describe("if true, create the pull request as a draft."),
|
||||
});
|
||||
interface GiteaPull { number: number; html_url?: string; title?: string; head?: { ref?: string }; base?: { ref?: string } }
|
||||
|
||||
function buildPrBodyWithFooter(ctx: ToolContext, body: string): string {
|
||||
const footer = buildShockbotFooter({ model: ctx.toolState.model });
|
||||
return `${stripExistingFooter(fixDoubleEscapedString(body))}${footer}`;
|
||||
return `${stripExistingFooter(fixDoubleEscapedString(body))}${buildShockbotFooter({ model: ctx.toolState.model })}`;
|
||||
}
|
||||
|
||||
export const UpdatePullRequestBody = type({
|
||||
@@ -29,19 +23,25 @@ export function UpdatePullRequestBodyTool(ctx: ToolContext) {
|
||||
description: "Update the body/description of an existing pull request",
|
||||
parameters: UpdatePullRequestBody,
|
||||
execute: execute(async (params) => {
|
||||
const result = await ctx.gitea.rest.repository.repoEditPullRequest({
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.name,
|
||||
index: params.pull_number,
|
||||
body: { body: buildPrBodyWithFooter(ctx, params.body) },
|
||||
});
|
||||
log.info(`» updated pull request #${result.data.number}`);
|
||||
const r = await ctx.gitea.request(
|
||||
"PATCH /repos/{owner}/{repo}/pulls/{index}",
|
||||
{ owner: ctx.repo.owner, repo: ctx.repo.name, index: params.pull_number, body: buildPrBodyWithFooter(ctx, params.body) }
|
||||
);
|
||||
const data = r.data as GiteaPull;
|
||||
log.info(`» updated pull request #${data.number}`);
|
||||
ctx.toolState.wasUpdated = true;
|
||||
return { success: true, number: result.data.number, url: result.data.html_url };
|
||||
return { success: true, number: data.number, url: data.html_url };
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export const PullRequest = type({
|
||||
title: type.string.describe("the title of the pull request"),
|
||||
body: type.string.describe("the body content of the pull request"),
|
||||
base: type.string.describe("the base branch to merge into (e.g., 'main')"),
|
||||
"draft?": type.boolean,
|
||||
});
|
||||
|
||||
export function CreatePullRequestTool(ctx: ToolContext) {
|
||||
return tool({
|
||||
name: "create_pull_request",
|
||||
@@ -49,42 +49,27 @@ export function CreatePullRequestTool(ctx: ToolContext) {
|
||||
parameters: PullRequest,
|
||||
execute: execute(async (params) => {
|
||||
const currentBranch = $("git", ["rev-parse", "--abbrev-ref", "HEAD"], { log: false }).trim();
|
||||
|
||||
const result = await ctx.gitea.rest.repository.repoCreatePullRequest({
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.name,
|
||||
body: {
|
||||
title: params.title,
|
||||
body: buildPrBodyWithFooter(ctx, params.body),
|
||||
head: currentBranch,
|
||||
base: params.base,
|
||||
// draft: params.draft ?? false, // not in all Gitea versions
|
||||
},
|
||||
});
|
||||
log.info(`» created pull request #${result.data.number}`);
|
||||
const r = await ctx.gitea.request(
|
||||
"POST /repos/{owner}/{repo}/pulls",
|
||||
{
|
||||
owner: ctx.repo.owner, repo: ctx.repo.name,
|
||||
title: params.title, body: buildPrBodyWithFooter(ctx, params.body),
|
||||
head: currentBranch, base: params.base,
|
||||
}
|
||||
);
|
||||
const data = r.data as GiteaPull;
|
||||
log.info(`» created pull request #${data.number}`);
|
||||
|
||||
const reviewer = ctx.payload.triggerer;
|
||||
if (reviewer && result.data.number) {
|
||||
if (reviewer && data.number) {
|
||||
try {
|
||||
await ctx.gitea.rest.repository.repoCreatePullReviewRequests({
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.name,
|
||||
index: result.data.number,
|
||||
body: { reviewers: [reviewer] },
|
||||
});
|
||||
} catch {
|
||||
log.debug(`failed to request review from ${reviewer}`);
|
||||
}
|
||||
await ctx.gitea.request(
|
||||
"POST /repos/{owner}/{repo}/pulls/{index}/requested_reviewers",
|
||||
{ owner: ctx.repo.owner, repo: ctx.repo.name, index: data.number, reviewers: [reviewer] }
|
||||
);
|
||||
} catch { log.debug(`failed to request review from ${reviewer}`); }
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
number: result.data.number,
|
||||
url: result.data.html_url,
|
||||
title: result.data.title,
|
||||
head: result.data.head?.label ?? result.data.head?.ref,
|
||||
base: result.data.base?.label ?? result.data.base?.ref,
|
||||
};
|
||||
return { success: true, number: data.number, url: data.html_url, title: data.title, head: data.head?.ref, base: data.base?.ref };
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user