Skip to content

Commit 074e761

Browse files
feat: add view PR checks tool (#768)
1 parent 0dc9974 commit 074e761

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/codegen/extensions/langchain/tools.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from codegen.extensions.linear.linear_client import LinearClient
99
from codegen.extensions.tools.bash import run_bash_command
1010
from codegen.extensions.tools.github.search import search
11+
from codegen.extensions.tools.github.view_pr_checks import view_pr_checks
1112
from codegen.extensions.tools.linear.linear import (
1213
linear_comment_on_issue_tool,
1314
linear_create_issue_tool,
@@ -669,6 +670,28 @@ def _run(
669670
return result.render()
670671

671672

673+
class GithubViewPRCheckInput(BaseModel):
674+
"""Input for viewing PR checks"""
675+
676+
pr_number: int = Field(..., description="The PR number to view checks for")
677+
678+
679+
class GithubViewPRCheckTool(BaseTool):
680+
"""Tool for viewing PR checks."""
681+
682+
name: ClassVar[str] = "view_pr_checks"
683+
description: ClassVar[str] = "View the check suites for a PR"
684+
args_schema: ClassVar[type[BaseModel]] = GithubCreatePRReviewCommentInput
685+
codebase: Codebase = Field(exclude=True)
686+
687+
def __init__(self, codebase: Codebase) -> None:
688+
super().__init__(codebase=codebase)
689+
690+
def _run(self, pr_number: int) -> str:
691+
result = view_pr_checks(self.codebase, pr_number=pr_number)
692+
return result.render()
693+
694+
672695
########################################################################################################################
673696
# LINEAR
674697
########################################################################################################################
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Tool for creating PR review comments."""
2+
3+
import json
4+
5+
from pydantic import Field
6+
7+
from codegen.sdk.core.codebase import Codebase
8+
9+
from ..observation import Observation
10+
11+
12+
class PRCheckObservation(Observation):
13+
"""Response from retrieving PR checks."""
14+
15+
pr_number: int = Field(
16+
description="PR number that was viewed",
17+
)
18+
head_sha: str | None = Field(
19+
description="SHA of the head commit",
20+
)
21+
summary: str | None = Field(
22+
description="Summary of the checks",
23+
)
24+
25+
26+
def view_pr_checks(codebase: Codebase, pr_number: int) -> PRCheckObservation:
27+
"""Retrieve check information from a Github PR .
28+
29+
Args:
30+
codebase: The codebase to operate on
31+
pr_number: The PR number to view checks on
32+
"""
33+
try:
34+
pr = codebase.op.remote_git_repo.get_pull_safe(pr_number)
35+
if not pr:
36+
return PRCheckObservation(
37+
pr_number=pr_number,
38+
head_sha=None,
39+
summary=None,
40+
)
41+
commit = codebase.op.remote_git_repo.get_commit_safe(pr.head.sha)
42+
all_check_suites = commit.get_check_suites()
43+
return PRCheckObservation(
44+
pr_number=pr_number,
45+
head_sha=pr.head.sha,
46+
summary="\n".join([json.dumps(check_suite.raw_data) for check_suite in all_check_suites]),
47+
)
48+
49+
except Exception as e:
50+
return PRCheckObservation(
51+
pr_number=pr_number,
52+
head_sha=None,
53+
summary=None,
54+
)

0 commit comments

Comments
 (0)