mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-07 02:22:12 +00:00
fix: dont open PRs when completed (#761)
This commit is contained in:
parent
210c848997
commit
c42638f9a3
3 changed files with 47 additions and 4 deletions
|
|
@ -14,7 +14,7 @@ import {
|
||||||
} from "../../../utils/github/git.js";
|
} from "../../../utils/github/git.js";
|
||||||
import {
|
import {
|
||||||
createPullRequest,
|
createPullRequest,
|
||||||
markPullRequestReadyForReview,
|
updatePullRequest,
|
||||||
} from "../../../utils/github/api.js";
|
} from "../../../utils/github/api.js";
|
||||||
import { createLogger, LogLevel } from "../../../utils/logger.js";
|
import { createLogger, LogLevel } from "../../../utils/logger.js";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
@ -44,6 +44,7 @@ import {
|
||||||
GitHubPullRequestUpdate,
|
GitHubPullRequestUpdate,
|
||||||
} from "../../../utils/github/types.js";
|
} from "../../../utils/github/types.js";
|
||||||
import { getRepoAbsolutePath } from "@open-swe/shared/git";
|
import { getRepoAbsolutePath } from "@open-swe/shared/git";
|
||||||
|
import { GITHUB_USER_LOGIN_HEADER } from "@open-swe/shared/constants";
|
||||||
|
|
||||||
const logger = createLogger(LogLevel.INFO, "Open PR");
|
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 { title, body } = toolCall.args as z.infer<typeof openPrTool.schema>;
|
||||||
|
|
||||||
|
const userLogin = config.configurable?.[GITHUB_USER_LOGIN_HEADER];
|
||||||
|
|
||||||
const prForTask = getPullRequestNumberFromActiveTask(
|
const prForTask = getPullRequestNumberFromActiveTask(
|
||||||
updatedTaskPlan ?? state.taskPlan,
|
updatedTaskPlan ?? state.taskPlan,
|
||||||
);
|
);
|
||||||
|
|
@ -195,17 +198,17 @@ export async function openPullRequest(
|
||||||
repo,
|
repo,
|
||||||
headBranch: branchName,
|
headBranch: branchName,
|
||||||
title,
|
title,
|
||||||
body: `Fixes #${state.githubIssueId}\n\n${body}`,
|
body: `Fixes #${state.githubIssueId}${userLogin ? `\n\nOwner: @${userLogin}` : ""}\n\n${body}`,
|
||||||
githubInstallationToken,
|
githubInstallationToken,
|
||||||
baseBranch: state.targetRepository.branch,
|
baseBranch: state.targetRepository.branch,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Ensure the PR is ready for review
|
// Ensure the PR is ready for review
|
||||||
pullRequest = await markPullRequestReadyForReview({
|
pullRequest = await updatePullRequest({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
title,
|
title,
|
||||||
body: `Fixes #${state.githubIssueId}\n\n${body}`,
|
body: `Fixes #${state.githubIssueId}${userLogin ? `\n\nOwner: @${userLogin}` : ""}\n\n${body}`,
|
||||||
pullNumber: prForTask,
|
pullNumber: prForTask,
|
||||||
githubInstallationToken,
|
githubInstallationToken,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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({
|
export async function getIssue({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import { toast } from "sonner";
|
||||||
import { DEFAULT_CONFIG_KEY, useConfigStore } from "@/hooks/useConfigStore";
|
import { DEFAULT_CONFIG_KEY, useConfigStore } from "@/hooks/useConfigStore";
|
||||||
import {
|
import {
|
||||||
API_KEY_REQUIRED_MESSAGE,
|
API_KEY_REQUIRED_MESSAGE,
|
||||||
|
GITHUB_USER_LOGIN_HEADER,
|
||||||
MANAGER_GRAPH_ID,
|
MANAGER_GRAPH_ID,
|
||||||
} from "@open-swe/shared/constants";
|
} from "@open-swe/shared/constants";
|
||||||
import { ManagerGraphUpdate } from "@open-swe/shared/open-swe/manager/types";
|
import { ManagerGraphUpdate } from "@open-swe/shared/open-swe/manager/types";
|
||||||
|
|
@ -163,6 +164,7 @@ export function TerminalInput({
|
||||||
recursion_limit: 400,
|
recursion_limit: 400,
|
||||||
configurable: {
|
configurable: {
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
|
[GITHUB_USER_LOGIN_HEADER]: user.login,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ifNotExists: "create",
|
ifNotExists: "create",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue