From 8a30e9a6c8ef79916393ad895ec4a4903dcc55bd Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 22:50:46 +0000 Subject: [PATCH 1/3] Add edit_pr tool with clear message about not pushing code changes --- .../extensions/tools/github/edit_pr.py | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/codegen/extensions/tools/github/edit_pr.py diff --git a/src/codegen/extensions/tools/github/edit_pr.py b/src/codegen/extensions/tools/github/edit_pr.py new file mode 100644 index 000000000..3178c72a1 --- /dev/null +++ b/src/codegen/extensions/tools/github/edit_pr.py @@ -0,0 +1,89 @@ +"""Tool for editing a PR's title, body, and/or state.""" + +from typing import Optional + +from github.PullRequest import PullRequest + +from codegen.extensions.tools.observation import Observation +from codegen.sdk.core.codebase import Codebase + + +def edit_pr( + codebase: Codebase, + pr_number: int, + title: Optional[str] = None, + body: Optional[str] = None, + state: Optional[str] = None, +) -> Observation: + """Edit a PR's title, body, and/or state. + + Args: + codebase: The codebase to operate on + pr_number: The PR number to edit + title: The new title for the PR (optional) + body: The new body/description for the PR (optional) + state: The new state for the PR (optional, can be 'open', 'closed', 'draft', or 'ready_for_review') + + Returns: + Observation with the result of the operation + """ + repo = codebase.git_client.get_repo() + if not repo: + return Observation( + success=False, + message=f"Failed to get repository for PR #{pr_number}", + ) + + try: + pr: PullRequest = repo.get_pull(pr_number) + except Exception as e: + return Observation( + success=False, + message=f"Failed to get PR #{pr_number}: {e}", + ) + + # Track what was updated + updates = [] + + # Update title if provided + if title is not None: + pr.edit(title=title) + updates.append("title") + + # Update body if provided + if body is not None: + pr.edit(body=body) + updates.append("body") + + # Update state if provided + if state is not None: + state = state.lower() + if state == "closed": + pr.edit(state="closed") + updates.append("state (closed)") + elif state == "open": + pr.edit(state="open") + updates.append("state (opened)") + elif state == "draft": + pr.as_draft() + updates.append("state (converted to draft)") + elif state == "ready_for_review": + pr.ready_for_review() + updates.append("state (marked ready for review)") + else: + return Observation( + success=False, + message=f"Invalid state '{state}'. Must be one of: 'open', 'closed', 'draft', or 'ready_for_review'", + ) + + if not updates: + return Observation( + success=True, + message=f"No changes were made to PR #{pr_number}. Please provide at least one of: title, body, or state.", + ) + + return Observation( + success=True, + message=f"Successfully updated PR #{pr_number} ({', '.join(updates)}). Note that this tool only updates PR metadata and does not push code changes to the PR branch. To add code changes to a PR, make your edits and then use the `create_pr` tool while on the PR branch.", + url=pr.html_url, + ) \ No newline at end of file From ef185605e8c74598aef672169f05d1b848695837 Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 22:51:39 +0000 Subject: [PATCH 2/3] Automated pre-commit update --- src/codegen/extensions/tools/github/edit_pr.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/codegen/extensions/tools/github/edit_pr.py b/src/codegen/extensions/tools/github/edit_pr.py index 3178c72a1..a9ebdb999 100644 --- a/src/codegen/extensions/tools/github/edit_pr.py +++ b/src/codegen/extensions/tools/github/edit_pr.py @@ -1,12 +1,13 @@ """Tool for editing a PR's title, body, and/or state.""" -from typing import Optional - -from github.PullRequest import PullRequest +from typing import TYPE_CHECKING, Optional from codegen.extensions.tools.observation import Observation from codegen.sdk.core.codebase import Codebase +if TYPE_CHECKING: + from github.PullRequest import PullRequest + def edit_pr( codebase: Codebase, @@ -86,4 +87,4 @@ def edit_pr( success=True, message=f"Successfully updated PR #{pr_number} ({', '.join(updates)}). Note that this tool only updates PR metadata and does not push code changes to the PR branch. To add code changes to a PR, make your edits and then use the `create_pr` tool while on the PR branch.", url=pr.html_url, - ) \ No newline at end of file + ) From bb5914d15144a505e8fc3cae5457ff217a8b3a9d Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 23:46:02 +0000 Subject: [PATCH 3/3] Fix pre-commit issues in PR #915 and add missing tools to get_workspace_tools --- src/codegen/extensions/langchain/tools.py | 46 ++++++++++++++++++- .../extensions/tools/github/edit_pr.py | 6 ++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/codegen/extensions/langchain/tools.py b/src/codegen/extensions/langchain/tools.py index 3a1193be1..bbce881e5 100644 --- a/src/codegen/extensions/langchain/tools.py +++ b/src/codegen/extensions/langchain/tools.py @@ -13,6 +13,7 @@ from codegen.extensions.linear.linear_client import LinearClient from codegen.extensions.tools.bash import run_bash_command from codegen.extensions.tools.github.checkout_pr import checkout_pr +from codegen.extensions.tools.github.edit_pr import edit_pr from codegen.extensions.tools.github.view_pr_checks import view_pr_checks from codegen.extensions.tools.global_replacement_edit import replacement_edit_global from codegen.extensions.tools.linear.linear import ( @@ -515,6 +516,46 @@ def _run(self, title: str, body: str) -> str: return result.render() +class GithubEditPRInput(BaseModel): + """Input for editing a PR.""" + + pr_number: int = Field(..., description="The PR number to edit") + title: Optional[str] = Field(None, description="The new title for the PR (optional)") + body: Optional[str] = Field(None, description="The new body/description for the PR (optional)") + state: Optional[str] = Field( + None, + description="The new state for the PR (optional, can be 'open', 'closed', 'draft', or 'ready_for_review')" + ) + + +class GithubEditPRTool(BaseTool): + """Tool for editing a PR's title, body, and/or state.""" + + name: ClassVar[str] = "edit_pr" + description: ClassVar[str] = "Edit a PR's title and/or body and/or state. The (optional) state parameter can be 'open', 'closed', 'draft', or 'ready_for_review'." + args_schema: ClassVar[type[BaseModel]] = GithubEditPRInput + codebase: Codebase = Field(exclude=True) + + def __init__(self, codebase: Codebase) -> None: + super().__init__(codebase=codebase) + + def _run( + self, + pr_number: int, + title: Optional[str] = None, + body: Optional[str] = None, + state: Optional[str] = None, + ) -> str: + result = edit_pr( + self.codebase, + pr_number=pr_number, + title=title, + body=body, + state=state, + ) + return result.render() + + class GithubSearchIssuesInput(BaseModel): """Input for searching GitHub issues.""" @@ -657,7 +698,7 @@ class GithubViewPRCheckTool(BaseTool): name: ClassVar[str] = "view_pr_checks" description: ClassVar[str] = "View the check suites for a PR" - args_schema: ClassVar[type[BaseModel]] = GithubCreatePRReviewCommentInput + args_schema: ClassVar[type[BaseModel]] = GithubViewPRCheckInput codebase: Codebase = Field(exclude=True) def __init__(self, codebase: Codebase) -> None: @@ -876,9 +917,12 @@ def get_workspace_tools(codebase: Codebase) -> list["BaseTool"]: ReflectionTool(codebase), # Github GithubCreatePRTool(codebase), + GithubEditPRTool(codebase), GithubCreatePRCommentTool(codebase), GithubCreatePRReviewCommentTool(codebase), GithubViewPRTool(codebase), + GithubViewPRCheckTool(codebase), + GithubCheckoutPRTool(codebase), GithubSearchIssuesTool(codebase), # Linear LinearGetIssueTool(codebase), diff --git a/src/codegen/extensions/tools/github/edit_pr.py b/src/codegen/extensions/tools/github/edit_pr.py index a9ebdb999..03c90505c 100644 --- a/src/codegen/extensions/tools/github/edit_pr.py +++ b/src/codegen/extensions/tools/github/edit_pr.py @@ -85,6 +85,10 @@ def edit_pr( return Observation( success=True, - message=f"Successfully updated PR #{pr_number} ({', '.join(updates)}). Note that this tool only updates PR metadata and does not push code changes to the PR branch. To add code changes to a PR, make your edits and then use the `create_pr` tool while on the PR branch.", + message=( + f"Successfully updated PR #{pr_number} ({', '.join(updates)}). " + "Note that this tool only updates PR metadata and does not push code changes to the PR branch. " + "To add code changes to a PR, make your edits and then use the `create_pr` tool while on the PR branch." + ), url=pr.html_url, )