fix: dont open PRs when completed (#761)

This commit is contained in:
Brace Sproul 2025-08-14 11:43:20 -07:00 • committed by GitHub
parent 210c848997
commit c42638f9a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 4 deletions

View file

@ -14,7 +14,7 @@ import {
} from "../../../utils/github/git.js";
import {
createPullRequest,
markPullRequestReadyForReview,
updatePullRequest,
} from "../../../utils/github/api.js";
import { createLogger, LogLevel } from "../../../utils/logger.js";
import { z } from "zod";
@ -44,6 +44,7 @@ import {
GitHubPullRequestUpdate,
} from "../../../utils/github/types.js";
import { getRepoAbsolutePath } from "@open-swe/shared/git";
import { GITHUB_USER_LOGIN_HEADER } from "@open-swe/shared/constants";
const logger = createLogger(LogLevel.INFO, "Open PR");
@ -180,6 +181,8 @@ export async function openPullRequest(
const { title, body } = toolCall.args as z.infer<typeof openPrTool.schema>;
const userLogin = config.configurable?.[GITHUB_USER_LOGIN_HEADER];
const prForTask = getPullRequestNumberFromActiveTask(
updatedTaskPlan ?? state.taskPlan,
);
@ -195,17 +198,17 @@ export async function openPullRequest(
repo,
headBranch: branchName,
title,
body: `Fixes #${state.githubIssueId}\n\n${body}`,
body: `Fixes #${state.githubIssueId}${userLogin ? `\n\nOwner: @${userLogin}` : ""}\n\n${body}`,
githubInstallationToken,
baseBranch: state.targetRepository.branch,
});
} else {
// Ensure the PR is ready for review
pullRequest = await markPullRequestReadyForReview({
pullRequest = await updatePullRequest({
owner,
repo,
title,
body: `Fixes #${state.githubIssueId}\n\n${body}`,
body: `Fixes #${state.githubIssueId}${userLogin ? `\n\nOwner: @${userLogin}` : ""}\n\n${body}`,
pullNumber: prForTask,
githubInstallationToken,
});

View file

@ -317,6 +317,44 @@ export async function markPullRequestReadyForReview({
);
}
export async function updatePullRequest({
owner,
repo,
pullNumber,
title,
body,
githubInstallationToken,
}: {
owner: string;
repo: string;
pullNumber: number;
title?: string;
body?: string;
githubInstallationToken: string;
}) {
return withGitHubRetry(
async (token: string) => {
const octokit = new Octokit({
auth: token,
});
const { data: pullRequest } = await octokit.pulls.update({
owner,
repo,
pull_number: pullNumber,
...(title && { title }),
...(body && { body }),
});
return pullRequest;
},
githubInstallationToken,
"Failed to update pull request",
{ pullNumber, owner, repo },
1,
);
}
export async function getIssue({
owner,
repo,

View file

@ -16,6 +16,7 @@ import { toast } from "sonner";
import { DEFAULT_CONFIG_KEY, useConfigStore } from "@/hooks/useConfigStore";
import {
API_KEY_REQUIRED_MESSAGE,
GITHUB_USER_LOGIN_HEADER,
MANAGER_GRAPH_ID,
} from "@open-swe/shared/constants";
import { ManagerGraphUpdate } from "@open-swe/shared/open-swe/manager/types";
@ -163,6 +164,7 @@ export function TerminalInput({
recursion_limit: 400,
configurable: {
...defaultConfig,
[GITHUB_USER_LOGIN_HEADER]: user.login,
},
},
ifNotExists: "create",