-
Notifications
You must be signed in to change notification settings - Fork 6
feat(ecosystem): Implement cross-system issue synchronization #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ecosystem-sync-integration-before
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import asdict, dataclass | ||
| from datetime import datetime | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from django.utils import timezone | ||
|
|
||
| if TYPE_CHECKING: | ||
| from sentry.integrations.models import Integration | ||
| from sentry.integrations.services.integration import RpcIntegration | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class AssignmentSource: | ||
| source_name: str | ||
| integration_id: int | ||
| queued: datetime = timezone.now() | ||
|
|
||
| @classmethod | ||
| def from_integration(cls, integration: Integration | RpcIntegration) -> AssignmentSource: | ||
| return AssignmentSource( | ||
| source_name=integration.name, | ||
| integration_id=integration.id, | ||
| ) | ||
|
|
||
| def to_dict(self) -> dict[str, Any]: | ||
| return asdict(self) | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, input_dict: dict[str, Any]) -> AssignmentSource | None: | ||
| try: | ||
| return cls(**input_dict) | ||
| except (ValueError, TypeError): | ||
| return None | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||
| from typing import Any | ||||||
|
|
||||||
| from sentry.integrations.services.assignment_source import AssignmentSource | ||||||
| from sentry.testutils.cases import TestCase | ||||||
|
|
||||||
|
|
||||||
| class TestAssignmentSource(TestCase): | ||||||
| def test_from_dict_empty_array(self): | ||||||
| data: dict[str, Any] = {} | ||||||
| result = AssignmentSource.from_dict(data) | ||||||
| assert result is None | ||||||
|
|
||||||
| def test_from_dict_inalid_data(self): | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo in method name. The method name has a typo: - def test_from_dict_inalid_data(self):
+ def test_from_dict_invalid_data(self):📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| data = { | ||||||
| "foo": "bar", | ||||||
| } | ||||||
|
|
||||||
| result = AssignmentSource.from_dict(data) | ||||||
| assert result is None | ||||||
|
|
||||||
| def test_from_dict_valid_data(self): | ||||||
| data = {"source_name": "foo-source", "integration_id": 123} | ||||||
|
|
||||||
| result = AssignmentSource.from_dict(data) | ||||||
| assert result is not None | ||||||
| assert result.source_name == "foo-source" | ||||||
| assert result.integration_id == 123 | ||||||
|
|
||||||
| def test_to_dict(self): | ||||||
| source = AssignmentSource( | ||||||
| source_name="foo-source", | ||||||
| integration_id=123, | ||||||
| ) | ||||||
|
|
||||||
| result = source.to_dict() | ||||||
| assert result.get("queued") is not None | ||||||
| assert result.get("source_name") == "foo-source" | ||||||
| assert result.get("integration_id") == 123 | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix mutable default argument issue.
Using
timezone.now()as a default argument creates a mutable default that is evaluated at class definition time, not at instance creation time. This means all instances will have the same timestamp if created without explicitly providing aqueuedvalue.Alternatively, use a factory function:
You'll need to import
fieldfromdataclassesfor the second approach.📝 Committable suggestion
🤖 Prompt for AI Agents