Skip to content

Commit

Permalink
Notify users about the usage of deprecated webhooks
Browse files Browse the repository at this point in the history
Each time a deprecated webhook is hit, a notification is
created (without duplicating it) to be sent.
  • Loading branch information
humitos committed Nov 13, 2018
1 parent 1648006 commit bf8798d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions readthedocs/core/views/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from readthedocs.core.utils import trigger_build
from readthedocs.builds.constants import LATEST
from readthedocs.notifications.decorators import notify_deprecated_endpoint
from readthedocs.projects import constants
from readthedocs.projects.models import Project, Feature
from readthedocs.projects.tasks import sync_repository_task
Expand Down Expand Up @@ -141,6 +142,7 @@ def _build_url(url, projects, branches):


@csrf_exempt
@notify_deprecated_endpoint
def github_build(request): # noqa: D205
"""
GitHub webhook consumer.
Expand Down Expand Up @@ -196,6 +198,7 @@ def github_build(request): # noqa: D205


@csrf_exempt
@notify_deprecated_endpoint
def gitlab_build(request): # noqa: D205
"""
GitLab webhook consumer.
Expand Down Expand Up @@ -231,6 +234,7 @@ def gitlab_build(request): # noqa: D205


@csrf_exempt
@notify_deprecated_endpoint
def bitbucket_build(request):
"""
Consume webhooks from multiple versions of Bitbucket's API.
Expand Down Expand Up @@ -307,6 +311,7 @@ def bitbucket_build(request):


@csrf_exempt
@notify_deprecated_endpoint
def generic_build(request, project_id_or_slug=None):
"""
Generic webhook build endpoint.
Expand Down
35 changes: 35 additions & 0 deletions readthedocs/notifications/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-

import logging

from django.db.models import Q

from readthedocs.projects.models import Project
from readthedocs.projects.notifications import DeprecatedWebhookEndpointNotification

log = logging.getLogger(__name__)


def notify_deprecated_endpoint(function):
"""
Decorator to notify owners that the endpoint is DEPRECATED.
"""
def wrap(request, *args, project_id_or_slug=None, **kwargs):
try:
project = Project.objects.get(
Q(pk=project_id_or_slug) | Q(slug=project_id_or_slug),
)
except (Project.DoesNotExist, ValueError):
log.info('Project not found: slug=%s', project_id_or_slug)

# Send one notification to each owner of the project
for user in project.users.all():
notification = DeprecatedWebhookEndpointNotification(
project,
request,
user,
)
notification.send()
return function(request, *args, project_id_or_slug, **kwargs)

return wrap
7 changes: 7 additions & 0 deletions readthedocs/projects/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ class ResourceUsageNotification(Notification):
context_object_name = 'project'
subject = 'Builds for {{ project.name }} are using too many resources'
level = REQUIREMENT


class DeprecatedWebhookEndpointNotification(Notification):
name = 'deprecated_webhook_endpoint'
context_object_name = 'project'
subject = 'Project {{ project.name }} is using a deprecated webhook'
level = REQUIREMENT
5 changes: 5 additions & 0 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,3 +1364,8 @@ def finish_inactive_builds():
'Builds marked as "Terminated due inactivity": %s',
builds_finished,
)


@app.task
def send_deprecated_endpoint_notifications():
pass
5 changes: 5 additions & 0 deletions readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ def USE_PROMOS(self): # noqa
'schedule': crontab(minute=0, hour='*/3'),
'options': {'queue': 'web'},
},
'every-week-endpoint-deprecated-notifications': {
'task': 'readthedocs.projects.tasks.send_deprecated_endpoint_notifications',
'schedule': crontab(minute=0, hour='10', day_of_week='monday'),
'options': {'queue': 'web'},
},
}

# Docker
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Just a heads up, your project {{ project.name }} has configured a <em>DEPRECATED</em> webhook to trigger new builds and should be upgraded. Projects hitting these deprecated webhook will stop building on Jan 1, 2019. Please, update it soon!</p>

<p>To update the webhook your project is hitting, you need to go to the project's settings under your VCS service (GitHub, Bitbucket or GitLab) and remove the Read the Docs webhook from there.</p>

<p>Once you have done that, you need to go to your <a href="{% url "projects_integrations" project.slug %}">project's Integrations</a> under Read the Docs project's Admin, click integration and then in "Resync webhook" button.</p>

<p>Thanks!</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Your project {{ project.name }} has configured a <em>DEPRECATED</em> webhook to trigger new builds and should be upgraded. Projects hitting these deprecated webhooks will stop building on Jan 1, 2019. <a href="{% url "projects_integrations" project.slug %}">Please, update it soon!</a>

0 comments on commit bf8798d

Please sign in to comment.