Skip to content

Commit

Permalink
Revert "[feat] Add functionality for AI PR review" (#1643)
Browse files Browse the repository at this point in the history
Reverts #1501
  • Loading branch information
rohitvinnakota-codecov authored Dec 17, 2024
1 parent 3940f43 commit 183f2b5
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 707 deletions.
5 changes: 1 addition & 4 deletions src/seer/automation/autofix/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
PipelineStep,
PipelineStepTaskRequest,
)
from seer.automation.state import DbStateRunTypes
from seer.automation.steps import (
ParallelizedChainConditionalStep,
ParallelizedChainStep,
Expand Down Expand Up @@ -46,9 +45,7 @@ def get_retry_count(self) -> int:
)

@staticmethod
def _instantiate_context(
request: PipelineStepTaskRequest, _: DbStateRunTypes | None = None
) -> PipelineContext:
def _instantiate_context(request: PipelineStepTaskRequest) -> PipelineContext:
return AutofixContext.from_run_id(request.run_id)

def _invoke(self, **kwargs: Any) -> Any:
Expand Down
12 changes: 0 additions & 12 deletions src/seer/automation/codebase/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Literal, NotRequired, TypedDict
from pydantic import BaseModel
from pydantic_xml import attr

Expand Down Expand Up @@ -45,14 +44,3 @@ class SearchResult(BaseModel):
relative_path: str
matches: list[Match]
score: float


class GithubPrReviewComment(TypedDict):
commit_id: str
body: str
path: str
side: NotRequired[Literal["LEFT", "RIGHT"]]
line: NotRequired[int]
start_line: NotRequired[int]
start_side: NotRequired[Literal["LEFT", "RIGHT"]]
in_reply_to: NotRequired[str]
49 changes: 3 additions & 46 deletions src/seer/automation/codebase/repo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import tarfile
import tempfile
from enum import Enum
from typing import List, Literal, Optional
from typing_extensions import TypedDict
from typing import Literal

import requests
import sentry_sdk
from github import (
Auth,
Github,
GithubObject,
GithubException,
GithubIntegration,
InputGitTreeElement,
Expand All @@ -24,7 +22,6 @@

from seer.automation.autofix.utils import generate_random_string, sanitize_branch_name
from seer.automation.codebase.utils import get_language_from_path
from seer.automation.codebase.models import GithubPrReviewComment
from seer.automation.models import FileChange, FilePatch, InitializationError, RepoDefinition
from seer.automation.utils import detect_encoding
from seer.configuration import AppConfig
Expand Down Expand Up @@ -105,7 +102,6 @@ class RepoClientType(str, Enum):
READ = "read"
WRITE = "write"
CODECOV_UNIT_TEST = "codecov_unit_test"
CODECOV_PR_REVIEW = "codecov_pr_review"


class RepoClient:
Expand Down Expand Up @@ -185,20 +181,12 @@ def check_repo_read_access(repo: RepoDefinition):

return False

@staticmethod
def _extract_id_from_pr_url(pr_url: str):
"""
Extracts the repository path and PR/issue ID from the provided URL.
"""
pr_id = int(pr_url.split("/")[-1])
return pr_id

@classmethod
@functools.cache
def from_repo_definition(cls, repo_def: RepoDefinition, type: RepoClientType):
if type == RepoClientType.WRITE:
return cls(*get_write_app_credentials(), repo_def)
elif type == RepoClientType.CODECOV_UNIT_TEST or type == RepoClientType.CODECOV_PR_REVIEW:
elif type == RepoClientType.CODECOV_UNIT_TEST:
return cls(*get_codecov_unit_test_app_credentials(), repo_def)

return cls(*get_read_app_credentials(), repo_def)
Expand Down Expand Up @@ -286,6 +274,7 @@ def load_repo_to_tmp_dir(self, sha: str | None = None) -> tuple[str, str]:

return tmp_dir, tmp_repo_dir


def get_file_content(self, path: str, sha: str | None = None) -> tuple[str | None, str]:
logger.debug(f"Getting file contents for {path} in {self.repo.full_name} on sha {sha}")
if sha is None:
Expand Down Expand Up @@ -580,35 +569,3 @@ def post_unit_test_not_generated_message_to_original_pr(self, original_pr_url: s
response = requests.post(url, headers=headers, json=params)
response.raise_for_status()
return response.json()["html_url"]

def post_issue_comment(self, pr_url: str, comment: str):
"""
Create an issue comment on a GitHub issue (all pull requests are issues).
This can be used to create an overall PR comment instead of associated with a specific line.
See https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment
Note that expected input is pr_url NOT pr_html_url
"""
pr_id = self._extract_id_from_pr_url(pr_url)
issue = self.repo.get_issue(number=pr_id)
comment_obj = issue.create_comment(body=comment)
return comment_obj.html_url

def post_pr_review_comment(self, pr_url: str, comment: GithubPrReviewComment):
"""
Create a review comment on a GitHub pull request.
See https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request
Note that expected input is pr_url NOT pr_html_url
"""
pr_id = self._extract_id_from_pr_url(pr_url)
pr = self.repo.get_pull(number=pr_id)
commit = self.repo.get_commit(comment["commit_id"])

review_comment = pr.create_review_comment(
body=comment["body"],
commit=commit,
path=comment["path"],
line=comment.get("line", GithubObject.NotSet),
side=comment.get("side", GithubObject.NotSet),
start_line=comment.get("start_line", GithubObject.NotSet),
)
return review_comment.html_url
6 changes: 2 additions & 4 deletions src/seer/automation/codegen/codegen_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

from seer.automation.codebase.repo_client import RepoClient, RepoClientType
from seer.automation.codegen.codegen_event_manager import CodegenEventManager
from seer.automation.codegen.models import CodegenContinuation
from seer.automation.codegen.state import CodegenContinuationState
from seer.automation.models import RepoDefinition
from seer.automation.pipeline import PipelineContext
from seer.automation.state import DbStateRunTypes

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -34,8 +32,8 @@ def __init__(
logger.info(f"CodegenContext initialized with run_id {self.run_id}")

@classmethod
def from_run_id(cls, run_id: int, type: DbStateRunTypes = DbStateRunTypes.UNIT_TEST):
state = CodegenContinuationState(run_id, model=CodegenContinuation, type=type)
def from_run_id(cls, run_id: int):
state = CodegenContinuationState(run_id)
with state.update() as cur:
cur.mark_triggered()

Expand Down
17 changes: 1 addition & 16 deletions src/seer/automation/codegen/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
from enum import Enum
from typing import List, Union

from pydantic import BaseModel, Field

Expand Down Expand Up @@ -40,7 +39,7 @@ class CodegenPrReviewRequest(BaseModel):


class CodegenContinuation(CodegenState):
request: Union[CodegenUnitTestsRequest, CodegenPrReviewRequest]
request: CodegenUnitTestsRequest

def mark_triggered(self):
self.last_triggered_at = datetime.datetime.now()
Expand Down Expand Up @@ -86,17 +85,3 @@ class CodegenPrReviewStateResponse(BaseModel):
triggered_at: datetime.datetime
updated_at: datetime.datetime
completed_at: datetime.datetime | None = None


class CodePrReviewRequest(BaseComponentRequest):
diff: str


class CodePrReviewOutput(BaseComponentOutput):
class Comment(BaseModel):
path: str
line: int
body: str
start_line: int

comments: List[Comment]
99 changes: 0 additions & 99 deletions src/seer/automation/codegen/pr_review_coding_component.py

This file was deleted.

73 changes: 0 additions & 73 deletions src/seer/automation/codegen/pr_review_publisher.py

This file was deleted.

Loading

0 comments on commit 183f2b5

Please sign in to comment.