fix(gitlab): address follow-up review findings
HIGH severity fixes: - Fix GitlabIssueBatcher initialization with missing required parameters * Add project and project_dir parameters to batcher instantiation - Fix instance method save_batch now properly called on batcher instance (already fixed) MEDIUM severity fixes: - Fix timezone-naive datetime comparisons in bot_detection.py * Use datetime.now(timezone.utc) instead of datetime.now() * Import timezone from datetime module * Fix mark_reviewed to use timezone-aware timestamps - Fix test function indentation in test_gitlab_context_gatherer.py * Indent test_gather_handles_missing_ci to be inside TestGatherIntegration class * Test uses self parameter, so must be instance method
This commit is contained in:
@@ -344,23 +344,22 @@ class TestGatherIntegration:
|
||||
assert result.ci_status == "success"
|
||||
assert result.ci_pipeline_id == 456
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gather_handles_missing_ci(
|
||||
self, gatherer, mock_client, sample_mr_data, sample_changes_data, sample_commits
|
||||
):
|
||||
"""Test that gather handles missing CI pipeline gracefully."""
|
||||
mock_client.get_mr_async.return_value = sample_mr_data
|
||||
mock_client.get_mr_changes_async.return_value = sample_changes_data
|
||||
mock_client.get_mr_commits_async.return_value = sample_commits
|
||||
mock_client.get_mr_notes_async.return_value = []
|
||||
mock_client.get_mr_pipeline_async.return_value = None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gather_handles_missing_ci(
|
||||
self, gatherer, mock_client, sample_mr_data, sample_changes_data, sample_commits
|
||||
):
|
||||
"""Test that gather handles missing CI pipeline gracefully."""
|
||||
mock_client.get_mr_async.return_value = sample_mr_data
|
||||
mock_client.get_mr_changes_async.return_value = sample_changes_data
|
||||
mock_client.get_mr_commits_async.return_value = sample_commits
|
||||
mock_client.get_mr_notes_async.return_value = []
|
||||
mock_client.get_mr_pipeline_async.return_value = None
|
||||
result = await gatherer.gather()
|
||||
|
||||
result = await gatherer.gather()
|
||||
|
||||
# Should not fail, CI fields should be None
|
||||
assert result.ci_status is None
|
||||
assert result.ci_pipeline_id is None
|
||||
# Should not fail, CI fields should be None
|
||||
assert result.ci_status is None
|
||||
assert result.ci_pipeline_id is None
|
||||
|
||||
|
||||
class TestAIBotCommentDetection:
|
||||
|
||||
@@ -33,7 +33,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import logging
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -315,7 +315,7 @@ class BotDetector:
|
||||
|
||||
try:
|
||||
last_review = datetime.fromisoformat(last_review_str)
|
||||
time_since = datetime.now() - last_review
|
||||
time_since = datetime.now(timezone.utc) - last_review
|
||||
|
||||
if time_since < timedelta(minutes=self.COOLING_OFF_MINUTES):
|
||||
minutes_left = self.COOLING_OFF_MINUTES - (
|
||||
@@ -418,7 +418,7 @@ class BotDetector:
|
||||
self.state.reviewed_commits[mr_key].append(commit_sha)
|
||||
|
||||
# Update last review time
|
||||
self.state.last_review_times[mr_key] = datetime.now().isoformat()
|
||||
self.state.last_review_times[mr_key] = datetime.now(timezone.utc).isoformat()
|
||||
|
||||
# Save state
|
||||
self.state.save(self.state_dir)
|
||||
|
||||
@@ -162,6 +162,8 @@ class GitlabBatchProcessor:
|
||||
# Create batcher instance to call save_batch (instance method)
|
||||
batcher = GitlabIssueBatcher(
|
||||
gitlab_dir=self.gitlab_dir,
|
||||
project=self.config.project,
|
||||
project_dir=self.project_dir,
|
||||
similarity_threshold=0.7,
|
||||
)
|
||||
batcher.save_batch(batch)
|
||||
|
||||
Reference in New Issue
Block a user