Skip to content

Commit

Permalink
fix(ai-autofix): Accept git repo provider format from sentry (#272)
Browse files Browse the repository at this point in the history
Sentry side repo providers come in the format integrations:github etc

Fixes TIMESERIES-ANALYSIS-SERVICE-2N
  • Loading branch information
jennmueng authored Mar 2, 2024
1 parent 0966b64 commit e9c913c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/seer/automation/autofix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class IssueDetails(BaseModel):


class RepoDefinition(BaseModel):
provider: Literal["github"]
provider: str
owner: str
name: str

Expand Down
6 changes: 6 additions & 0 deletions src/seer/automation/codebase/repo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(
repo_owner: str,
repo_name: str,
):
repo_provider = self._process_repo_provider(repo_provider)
if repo_provider != "github":
# This should never get here, the repo provider should be checked on the Sentry side but this will make debugging
# easier if it does
Expand All @@ -71,6 +72,11 @@ def __init__(
self.repo_owner = repo_owner
self.repo_name = repo_name

def _process_repo_provider(self, provider: str) -> str:
if provider.startswith("integrations:"):
return provider.split(":")[1]
return provider

def get_default_branch(self):
return self.repo.default_branch

Expand Down
45 changes: 45 additions & 0 deletions tests/automation/codebase/test_repo_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest
from unittest.mock import patch

from seer.automation.codebase.repo_client import RepoClient
from seer.automation.models import InitializationError


class TestRepoClient(unittest.TestCase):
@patch("seer.automation.codebase.repo_client.Github")
@patch("seer.automation.codebase.repo_client.get_github_auth")
def test_repo_client_accepts_github_provider(self, mock_get_github_auth, mock_github):
# Mocking Github class and get_github_auth function to simulate GitHub API responses and authentication
mock_github_instance = mock_github.return_value
mock_github_instance.get_repo.return_value.default_branch = "main"
mock_get_github_auth.return_value = (
None # Assuming get_github_auth returns None for simplicity
)
client = RepoClient(repo_provider="github", repo_owner="test_owner", repo_name="test_repo")
self.assertEqual(client.provider, "github")

@patch("seer.automation.codebase.repo_client.Github")
@patch("seer.automation.codebase.repo_client.get_github_auth")
def test_repo_client_accepts_integrations_github_provider(
self, mock_get_github_auth, mock_github
):
# Mocking Github class and get_github_auth function to simulate GitHub API responses and authentication
mock_github_instance = mock_github.return_value
mock_github_instance.get_repo.return_value.default_branch = "main"
mock_get_github_auth.return_value = (
None # Assuming get_github_auth returns None for simplicity
)
client = RepoClient(
repo_provider="integrations:github", repo_owner="test_owner", repo_name="test_repo"
)
self.assertEqual(client.provider, "github")

@patch("seer.automation.codebase.repo_client.get_github_auth")
def test_repo_client_rejects_unsupported_provider(self, mock_get_github_auth):
mock_get_github_auth.return_value = (
None # Assuming get_github_auth returns None for simplicity
)
with self.assertRaises(InitializationError):
RepoClient(
repo_provider="unsupported_provider", repo_owner="test_owner", repo_name="test_repo"
)

0 comments on commit e9c913c

Please sign in to comment.