Skip to content

Commit c6f9352

Browse files
🛠️ apply pre-commit fixes
1 parent aba30a3 commit c6f9352

File tree

8 files changed

+155
-116
lines changed

8 files changed

+155
-116
lines changed

src/migrations/versions/8b858da8ed27_migration.py

+44-27
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,66 @@
55
Create Date: 2025-03-06 13:24:21.106144
66
77
"""
8-
from alembic import op
8+
99
import sqlalchemy as sa
10-
from sqlalchemy.dialects import postgresql
10+
from alembic import op
1111
from pgvector.sqlalchemy import Vector # type: ignore
12-
12+
from sqlalchemy.dialects import postgresql
1313

1414
# revision identifiers, used by Alembic.
15-
revision = '8b858da8ed27'
16-
down_revision = 'e0fcdc14251c'
15+
revision = "8b858da8ed27"
16+
down_revision = "e0fcdc14251c"
1717
branch_labels = None
1818
depends_on = None
1919

2020

2121
def upgrade():
2222
# ### commands auto generated by Alembic - please adjust! ###
23-
op.create_table('codegen_review_comments_pattern_store',
24-
sa.Column('id', sa.Integer(), nullable=False),
25-
sa.Column('provider', sa.String(), nullable=False),
26-
sa.Column('owner', sa.String(), nullable=False),
27-
sa.Column('repo', sa.String(), nullable=False),
28-
sa.Column('pr_id', sa.BigInteger(), nullable=False),
29-
sa.Column('body', sa.String(), nullable=False),
30-
sa.Column('is_good_pattern', sa.Boolean(), nullable=False),
31-
sa.Column('embedding', Vector(dim=768), nullable=False),
32-
sa.Column('comment_metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
33-
sa.Column('created_at', sa.DateTime(), nullable=False),
34-
sa.PrimaryKeyConstraint('id'),
35-
sa.UniqueConstraint('provider', 'pr_id', 'repo', 'owner')
23+
op.create_table(
24+
"codegen_review_comments_pattern_store",
25+
sa.Column("id", sa.Integer(), nullable=False),
26+
sa.Column("provider", sa.String(), nullable=False),
27+
sa.Column("owner", sa.String(), nullable=False),
28+
sa.Column("repo", sa.String(), nullable=False),
29+
sa.Column("pr_id", sa.BigInteger(), nullable=False),
30+
sa.Column("body", sa.String(), nullable=False),
31+
sa.Column("is_good_pattern", sa.Boolean(), nullable=False),
32+
sa.Column("embedding", Vector(dim=768), nullable=False),
33+
sa.Column("comment_metadata", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
34+
sa.Column("created_at", sa.DateTime(), nullable=False),
35+
sa.PrimaryKeyConstraint("id"),
36+
sa.UniqueConstraint("provider", "pr_id", "repo", "owner"),
3637
)
37-
with op.batch_alter_table('codegen_review_comments_pattern_store', schema=None) as batch_op:
38-
batch_op.create_index('ix_review_comments_embedding_hnsw', ['embedding'], unique=False, postgresql_using='hnsw', postgresql_with={'m': 16, 'ef_construction': 64}, postgresql_ops={'embedding': 'vector_cosine_ops'})
39-
batch_op.create_index('ix_review_comments_is_good_pattern', ['is_good_pattern'], unique=False)
40-
batch_op.create_index('ix_review_comments_repo_owner_pr', ['owner', 'repo', 'pr_id'], unique=False)
38+
with op.batch_alter_table("codegen_review_comments_pattern_store", schema=None) as batch_op:
39+
batch_op.create_index(
40+
"ix_review_comments_embedding_hnsw",
41+
["embedding"],
42+
unique=False,
43+
postgresql_using="hnsw",
44+
postgresql_with={"m": 16, "ef_construction": 64},
45+
postgresql_ops={"embedding": "vector_cosine_ops"},
46+
)
47+
batch_op.create_index(
48+
"ix_review_comments_is_good_pattern", ["is_good_pattern"], unique=False
49+
)
50+
batch_op.create_index(
51+
"ix_review_comments_repo_owner_pr", ["owner", "repo", "pr_id"], unique=False
52+
)
4153

4254
# ### end Alembic commands ###
4355

4456

4557
def downgrade():
4658
# ### commands auto generated by Alembic - please adjust! ###
47-
with op.batch_alter_table('codegen_review_comments_pattern_store', schema=None) as batch_op:
48-
batch_op.drop_index('ix_review_comments_repo_owner_pr')
49-
batch_op.drop_index('ix_review_comments_is_good_pattern')
50-
batch_op.drop_index('ix_review_comments_embedding_hnsw', postgresql_using='hnsw', postgresql_with={'m': 16, 'ef_construction': 64}, postgresql_ops={'embedding': 'vector_cosine_ops'})
59+
with op.batch_alter_table("codegen_review_comments_pattern_store", schema=None) as batch_op:
60+
batch_op.drop_index("ix_review_comments_repo_owner_pr")
61+
batch_op.drop_index("ix_review_comments_is_good_pattern")
62+
batch_op.drop_index(
63+
"ix_review_comments_embedding_hnsw",
64+
postgresql_using="hnsw",
65+
postgresql_with={"m": 16, "ef_construction": 64},
66+
postgresql_ops={"embedding": "vector_cosine_ops"},
67+
)
5168

52-
op.drop_table('codegen_review_comments_pattern_store')
69+
op.drop_table("codegen_review_comments_pattern_store")
5370
# ### end Alembic commands ###

src/seer/app.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
AutofixRequest,
2626
AutofixStateRequest,
2727
AutofixStateResponse,
28+
AutofixUpdateEndpointResponse,
2829
AutofixUpdateRequest,
2930
AutofixUpdateType,
3031
)
@@ -34,6 +35,7 @@
3435
get_autofix_state,
3536
get_autofix_state_from_pr_id,
3637
receive_user_message,
38+
resolve_comment_thread,
3739
restart_from_point_with_feedback,
3840
run_autofix_coding,
3941
run_autofix_evaluation,
@@ -48,6 +50,7 @@
4850
CodecovTaskRequest,
4951
CodegenBaseRequest,
5052
CodegenBaseResponse,
53+
CodegenPrClosedResponse,
5154
CodegenPrReviewResponse,
5255
CodegenPrReviewStateRequest,
5356
CodegenPrReviewStateResponse,
@@ -56,14 +59,13 @@
5659
CodegenUnitTestsResponse,
5760
CodegenUnitTestsStateRequest,
5861
CodegenUnitTestsStateResponse,
59-
CodegenPrClosedResponse,
6062
)
6163
from seer.automation.codegen.tasks import (
64+
codegen_pr_closed,
6265
codegen_pr_review,
6366
codegen_relevant_warnings,
6467
codegen_unittest,
6568
get_unittest_state,
66-
codegen_pr_closed
6769
)
6870
from seer.automation.summarize.issue import run_summarize_issue
6971
from seer.automation.summarize.models import SummarizeIssueRequest, SummarizeIssueResponse
@@ -186,15 +188,15 @@ def autofix_start_endpoint(data: AutofixRequest) -> AutofixEndpointResponse:
186188
@json_api(blueprint, "/v1/automation/autofix/update")
187189
def autofix_update_endpoint(
188190
data: AutofixUpdateRequest,
189-
) -> AutofixEndpointResponse:
191+
) -> AutofixUpdateEndpointResponse:
190192
if data.payload.type == AutofixUpdateType.SELECT_ROOT_CAUSE:
191193
run_autofix_solution(data)
192194
elif data.payload.type == AutofixUpdateType.SELECT_SOLUTION:
193195
run_autofix_coding(data)
194196
elif data.payload.type == AutofixUpdateType.CREATE_PR:
195-
run_autofix_push_changes(data)
197+
return run_autofix_push_changes(data)
196198
elif data.payload.type == AutofixUpdateType.CREATE_BRANCH:
197-
run_autofix_push_changes(data)
199+
return run_autofix_push_changes(data)
198200
elif data.payload.type == AutofixUpdateType.USER_MESSAGE:
199201
receive_user_message(data)
200202
elif data.payload.type == AutofixUpdateType.RESTART_FROM_POINT_WITH_FEEDBACK:
@@ -203,7 +205,10 @@ def autofix_update_endpoint(
203205
update_code_change(data)
204206
elif data.payload.type == AutofixUpdateType.COMMENT_THREAD:
205207
comment_on_thread(data)
206-
return AutofixEndpointResponse(started=True, run_id=data.run_id)
208+
elif data.payload.type == AutofixUpdateType.RESOLVE_COMMENT_THREAD:
209+
resolve_comment_thread(data)
210+
211+
return AutofixUpdateEndpointResponse(run_id=data.run_id)
207212

208213

209214
@json_api(blueprint, "/v1/automation/autofix/state")
@@ -383,7 +388,6 @@ def ready_check(app_config: AppConfig = injected):
383388
from seer.inference_models import models_loading_status
384389

385390
status = models_loading_status()
386-
logger.info(f"Model loading status: {status}")
387391
if app_config.SMOKE_CHECK:
388392
smoke_status = check_smoke_test()
389393
logger.info(f"Celery smoke status: {smoke_status}")

src/seer/automation/codegen/models.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,19 @@ class PrFile(BaseModel):
160160
# https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28
161161
filename: str
162162
patch: str
163-
status: Literal[
164-
"added",
165-
"removed",
166-
"modified",
167-
"renamed",
168-
"copied",
169-
"changed",
170-
"unchanged",
171-
]
163+
status: Literal["added", "removed", "modified", "renamed", "copied", "changed", "unchanged"]
172164
changes: int
173165

174166

167+
class FilterWarningsRequest(BaseComponentRequest):
168+
warnings: list[StaticAnalysisWarning]
169+
target_filenames: list[str]
170+
171+
172+
class FilterWarningsOutput(BaseComponentOutput):
173+
warnings: list[StaticAnalysisWarning]
174+
175+
175176
class CodeFetchIssuesRequest(BaseComponentRequest):
176177
organization_id: int
177178
pr_files: list[PrFile]
@@ -214,6 +215,11 @@ class CodePredictRelevantWarningsOutput(BaseComponentOutput):
214215

215216

216217
class CodecovTaskRequest(BaseModel):
217-
data: CodegenUnitTestsRequest | CodegenPrReviewRequest | CodegenRelevantWarningsRequest | CodegenPrClosedRequest
218+
data: (
219+
CodegenUnitTestsRequest
220+
| CodegenPrReviewRequest
221+
| CodegenRelevantWarningsRequest
222+
| CodegenPrClosedRequest
223+
)
218224
external_owner_id: str
219225
request_type: Literal["unit-tests", "pr-review", "relevant-warnings", "pr-closed"]

src/seer/automation/codegen/pr_closed_step.py

+22-23
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import datetime
12
from asyncio.log import logger
23
from typing import Any
4+
35
from github.PaginatedList import PaginatedList
46
from github.PullRequestComment import PullRequestComment
5-
import datetime
6-
77
from langfuse.decorators import observe
88
from sentry_sdk.ai.monitoring import ai_track
9+
from sqlalchemy.dialects.postgresql import insert
910

1011
from celery_app.app import celery_app
12+
from seer.automation.agent.embeddings import GoogleProviderEmbeddings
1113
from seer.automation.autofix.config import (
1214
AUTOFIX_EXECUTION_HARD_TIME_LIMIT_SECS,
1315
AUTOFIX_EXECUTION_SOFT_TIME_LIMIT_SECS,
@@ -18,8 +20,6 @@
1820
from seer.automation.pipeline import PipelineStepTaskRequest
1921
from seer.automation.state import DbStateRunTypes
2022
from seer.db import DbReviewCommentEmbedding, Session
21-
from seer.automation.agent.embeddings import GoogleProviderEmbeddings
22-
from sqlalchemy.dialects.postgresql import insert
2323

2424

2525
class PrClosedStepRequest(PipelineStepTaskRequest):
@@ -31,6 +31,7 @@ class CommentAnalyzer:
3131
"""
3232
Handles comment analysis logic
3333
"""
34+
3435
def __init__(self, bot_username: str = "codecov-ai-reviewer[bot]"):
3536
self.bot_username = bot_username
3637

@@ -44,10 +45,10 @@ def analyze_reactions(self, comment: PullRequestComment) -> tuple[bool, bool]:
4445
Returns: (is_good_pattern, is_bad_pattern)
4546
"""
4647
reactions = comment.get_reactions()
47-
upvotes = sum(1 for r in reactions if r.content == '+1')
48-
downvotes = sum(1 for r in reactions if r.content == '-1')
49-
50-
is_good_pattern = upvotes >= downvotes
48+
upvotes = sum(1 for r in reactions if r.content == "+1")
49+
downvotes = sum(1 for r in reactions if r.content == "-1")
50+
51+
is_good_pattern = upvotes >= downvotes
5152
is_bad_pattern = downvotes > upvotes
5253
return is_good_pattern, is_bad_pattern
5354

@@ -84,16 +85,15 @@ def __init__(self, request: dict[str, Any], type: DbStateRunTypes):
8485
def _process_comment(self, comment: PullRequestComment, pr):
8586
try:
8687
is_good_pattern, is_bad_pattern = self.analyzer.analyze_reactions(comment)
87-
88+
8889
logger.info(
8990
f"Processing bot comment id {comment.id} on PR {pr.url}: "
9091
f"good_pattern={is_good_pattern}, "
9192
f"bad_pattern={is_bad_pattern}"
9293
)
9394

9495
model = GoogleProviderEmbeddings.model(
95-
"text-embedding-005",
96-
task_type="CODE_RETRIEVAL_QUERY"
96+
"text-embedding-005", task_type="CODE_RETRIEVAL_QUERY"
9797
)
9898
# Returns a 2D array, even for a single text input
9999
embedding = model.encode(comment.body)[0]
@@ -109,17 +109,18 @@ def _process_comment(self, comment: PullRequestComment, pr):
109109
comment_metadata={
110110
"url": comment.html_url,
111111
"comment_id": comment.id,
112-
"location": {
113-
"file_path": comment.path,
114-
"line_number": comment.position
115-
} if hasattr(comment, "path") else None,
112+
"location": (
113+
{"file_path": comment.path, "line_number": comment.position}
114+
if hasattr(comment, "path")
115+
else None
116+
),
116117
"timestamps": {
117118
"created_at": comment.created_at.isoformat(),
118119
"updated_at": comment.updated_at.isoformat(),
119-
}
120+
},
120121
},
121122
embedding=embedding,
122-
created_at=datetime.datetime.now()
123+
created_at=datetime.datetime.now(),
123124
)
124125

125126
session.execute(
@@ -128,11 +129,9 @@ def _process_comment(self, comment: PullRequestComment, pr):
128129
)
129130
)
130131
session.commit()
131-
132+
132133
except Exception as e:
133-
self.logger.error(
134-
f"Error processing comment {comment.id} on PR {pr.url}: {e}"
135-
)
134+
self.logger.error(f"Error processing comment {comment.id} on PR {pr.url}: {e}")
136135
raise
137136

138137
@observe(name="Codegen - PR Closed")
@@ -152,7 +151,7 @@ def _invoke(self, **kwargs):
152151
self._process_comment(comment, pr)
153152

154153
self.context.event_manager.mark_completed()
155-
154+
156155
except Exception as e:
157156
self.logger.error(f"Error processing closed PR {pr.url}: {e}")
158-
raise
157+
raise

src/seer/automation/codegen/tasks.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def create_initial_pr_review_run(request: CodegenBaseRequest) -> DbState[Codegen
4848

4949
return state
5050

51+
5152
def create_initial_pr_closed_run(request: CodegenPrClosedRequest) -> DbState[CodegenContinuation]:
5253
state = CodegenContinuationState.new(
5354
CodegenContinuation(request=request), group_id=request.pr_id, t=DbStateRunTypes.PR_CLOSED
@@ -59,7 +60,6 @@ def create_initial_pr_closed_run(request: CodegenPrClosedRequest) -> DbState[Cod
5960
cur.mark_triggered()
6061

6162
return state
62-
6363

6464

6565
def create_initial_relevant_warnings_run(
@@ -109,16 +109,15 @@ def codegen_pr_closed(request: CodegenBaseRequest, app_config: AppConfig = injec
109109
run_id=cur_state.run_id,
110110
pr_id=request.pr_id,
111111
repo_definition=request.repo,
112-
)
113-
112+
)
113+
114114
PrClosedStep.get_signature(
115115
pr_closed_request, queue=app_config.CELERY_WORKER_QUEUE
116116
).apply_async()
117117

118118
return CodegenPrClosedResponse(run_id=cur_state.run_id)
119119

120120

121-
122121
def get_unittest_state(request: CodegenUnitTestsStateRequest):
123122
state = CodegenContinuationState(request.run_id)
124123
return state.get()

0 commit comments

Comments
 (0)