Skip to content

Commit

Permalink
feat(servicehooks): Update servicehook URLs (#14093)
Browse files Browse the repository at this point in the history
Updates the group and event URLs in servicehooks to align with the new
Sentry 10 routes. Also uses the hex event ID instead of the deprecated
autoincrement ID.
  • Loading branch information
lynnagara authored Jul 19, 2019
1 parent 1985cd4 commit 7cd4e9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/sentry/tasks/servicehooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,19 @@
from sentry.models import ServiceHook
from sentry.tasks.base import instrumented_task
from sentry.utils import json
from sentry.utils.http import absolute_uri


def get_payload_v0(event):
group = event.group
project = group.project

project_url_base = absolute_uri(u'/{}/{}'.format(
project.organization.slug,
project.slug,
))

group_context = serialize(group)
group_context['url'] = u'{}/issues/{}/'.format(
project_url_base,
group.id,
)
group_context['url'] = group.get_absolute_url()

event_context = serialize(event)
event_context['url'] = u'{}/issues/{}/events/{}/'.format(
project_url_base,
group.id,
event.id,
event_context['url'] = u'{}events/{}/'.format(
group.get_absolute_url(),
event.event_id,
)
data = {
'project': {
Expand Down
15 changes: 15 additions & 0 deletions tests/sentry/tasks/test_servicehooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,18 @@ def test_event_created_sends_service_hook(self, safe_urlopen):
'X-ServiceHook-GUID',
'X-ServiceHook-Signature',
))

def test_v0_payload(self):
event = self.create_event(project=self.project)

process_service_hook(self.hook.id, event)
body = get_payload_v0(event)
assert body['group']['url'] == 'http://testserver/organizations/{}/issues/{}/'.format(
self.organization.slug,
event.group.id,
)
assert body['event']['url'] == 'http://testserver/organizations/{}/issues/{}/events/{}/'.format(
self.organization.slug,
event.group.id,
event.event_id,
)

0 comments on commit 7cd4e9e

Please sign in to comment.