Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/sentry/integrations/github/handlers/github_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,36 @@
class GithubActionHandler(TicketingActionHandler):
group = ActionHandler.Group.TICKET_CREATION
provider_slug = IntegrationProviderSlug.GITHUB

data_schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"description": "Schema for GitHub ticket creation action data blob",
"properties": {
"dynamic_form_fields": {
"type": "array",
"description": "Dynamic form fields from customer configuration",
"items": {"type": "object"},
"default": [],
},
"additional_fields": {
"type": "object",
"description": "Additional fields that aren't part of standard fields",
"additionalProperties": True,
"properties": {
"repo": {"type": "string"},
"labels": {
"type": ["array", "null"],
"items": {"type": "string"},
"default": [],
},
"assignee": {
"type": ["string", "null"],
},
},
"required": ["repo"],
Comment thread
joshuarli marked this conversation as resolved.
},
},
"required": ["additional_fields"],
"additionalProperties": False,
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from sentry.integrations.github.handlers.github_handler import GithubActionHandler
from sentry.integrations.types import IntegrationProviderSlug
from sentry.notifications.notification_action.action_handler_registry.base import (
TicketingActionHandler,
)
from sentry.workflow_engine.models import Action
from sentry.workflow_engine.registry import action_handler_registry
from sentry.workflow_engine.types import ActionHandler


@action_handler_registry.register(Action.Type.GITHUB_ENTERPRISE)
class GithubEnterpriseActionHandler(TicketingActionHandler):
class GithubEnterpriseActionHandler(GithubActionHandler):
group = ActionHandler.Group.TICKET_CREATION
provider_slug = IntegrationProviderSlug.GITHUB_ENTERPRISE
6 changes: 6 additions & 0 deletions tests/sentry/api/serializers/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
from django.utils import timezone
from rest_framework import serializers

# Explicit imports so selective testing can detect when these handlers change.
# They register via @action_handler_registry.register at import time (startup
# side-effect), so without these the static scanner has no edge from handler
# files to this test file.
import sentry.integrations.github.handlers # noqa: F401
import sentry.integrations.github_enterprise.handlers # noqa: F401
from sentry.api.serializers import serialize
from sentry.api.serializers.models.rule import RuleSerializer, WorkflowEngineRuleSerializer
from sentry.integrations.models import OrganizationIntegration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def test_validate(self) -> None:
assert result is True


class TestGitHubActionValidator(BaseTicketingActionValidatorTest):
def setUp(self) -> None:
super().setUp()
self.valid_data["data"] = {
"additional_fields": {"repo": "owner/test-repo", "integration": "12345"}
}


class TestJiraActionValidator(BaseTicketingActionValidatorTest):
__test__ = True
provider = Action.Type.JIRA
Expand All @@ -47,11 +55,27 @@ class TestAzureDevOpsActionValidator(BaseTicketingActionValidatorTest):
provider = Action.Type.AZURE_DEVOPS


class TestGithubActionValidator(BaseTicketingActionValidatorTest):
class TestGithubActionValidator(TestGitHubActionValidator):
__test__ = True
provider = Action.Type.GITHUB

def test_validate_missing_repo(self) -> None:
data = {**self.valid_data, "data": {}}
validator = BaseActionValidator(
data=data,
context={"organization": self.organization},
)
assert validator.is_valid() is False


class TestGithubEnterpriseActionValidator(BaseTicketingActionValidatorTest):
class TestGithubEnterpriseActionValidator(TestGitHubActionValidator):
__test__ = True
provider = Action.Type.GITHUB_ENTERPRISE

def test_validate_missing_repo(self) -> None:
data = {**self.valid_data, "data": {}}
validator = BaseActionValidator(
data=data,
context={"organization": self.organization},
)
assert validator.is_valid() is False
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ def test_action_type_in_migration(self) -> None:
{
"integration": "1",
"id": "sentry.integrations.github.notify_action.GitHubCreateTicketAction",
"repo": "owner/repo",
"uuid": "test-uuid",
},
Action.Type.GITHUB,
Expand All @@ -843,6 +844,7 @@ def test_action_type_in_migration(self) -> None:
{
"integration": "1",
"id": "sentry.integrations.github_enterprise.notify_action.GitHubEnterpriseCreateTicketAction",
"repo": "owner/repo",
"uuid": "test-uuid",
},
Action.Type.GITHUB_ENTERPRISE,
Expand Down
Loading