Beispiel #1
0
def create_link(
    integration: Integration,
    installation: IntegrationInstallation,
    event: Event,
    response: Response,
) -> None:
    """
    After creating the event on a third-party service, create a link to the
    external resource in the DB. TODO make this a transaction.
    :param integration: Integration object.
    :param installation: Installation object.
    :param event: The event object that was recorded on an external service.
    :param response: The API response from creating the new resource.
        - key: String. The unique ID of the external resource
        - metadata: Optional Object. Can contain `display_name`.
    """
    external_issue = ExternalIssue.objects.create(
        organization_id=event.group.project.organization_id,
        integration_id=integration.id,
        key=response["key"],
        title=event.title,
        description=installation.get_group_description(event.group, event),
        metadata=response.get("metadata"),
    )
    GroupLink.objects.create(
        group_id=event.group.id,
        project_id=event.group.project_id,
        linked_type=GroupLink.LinkedType.issue,
        linked_id=external_issue.id,
        relationship=GroupLink.Relationship.references,
        data={"provider": integration.provider},
    )
Beispiel #2
0
def build_description(
    event: Event,
    rule_id: int,
    installation: IntegrationInstallation,
    generate_footer: Callable[[str], str],
) -> str:
    """
    Format the description of the ticket/work item
    """
    project = event.group.project
    rule_url = f"/organizations/{project.organization.slug}/alerts/rules/{project.slug}/{rule_id}/"

    description: str = installation.get_group_description(event.group, event) + generate_footer(
        rule_url
    )
    return description
Beispiel #3
0
    def _validate_repo(self, client: Any,
                       installation: IntegrationInstallation,
                       repo: str) -> JSONData:
        try:
            repo_data = client.get_repo(repo)
        except Exception as e:
            raise installation.raise_error(e)

        try:
            # make sure installation has access to this specific repo
            # use hooks endpoint since we explicitly ask for those permissions
            # when installing the app (commits can be accessed for public repos)
            # https://developer.github.com/v3/repos/hooks/#list-hooks
            client.repo_hooks(repo)
        except ApiError:
            raise IntegrationError(f"You must grant Sentry access to {repo}")

        return repo_data
    def test_with_context(self):
        integration = IntegrationInstallation(self.model, self.organization.id)

        assert integration.model == self.model
        assert integration.org_integration == self.org_integration
        assert integration.get_default_identity() == self.identity
 def test_no_context(self):
     integration = IntegrationInstallation(self.model, self.organization.id)
     integration.name = 'Base'
Beispiel #6
0
def should_comment_sync(installation: IntegrationInstallation,
                        external_issue: ExternalIssue) -> bool:
    organization = Organization.objects.get(id=external_issue.organization_id)
    has_issue_sync = features.has("organizations:integrations-issue-sync",
                                  organization)
    return has_issue_sync and installation.should_sync("comment")
Beispiel #7
0
    def test_with_context(self):
        integration = IntegrationInstallation(self.model, self.organization.id)

        assert integration.model == self.model
        assert integration.org_integration == self.org_integration
        assert integration.get_default_identity() == self.identity
Beispiel #8
0
 def test_no_context(self):
     integration = IntegrationInstallation(self.model, self.organization.id)
     integration.name = 'Base'