Skip to content
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

Make restapi URL additions conditional #4609

Merged
merged 3 commits into from
Sep 6, 2018
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
2 changes: 1 addition & 1 deletion common
132 changes: 91 additions & 41 deletions readthedocs/restapi/urls.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
"""Define routes between URL paths and views/endpoints."""
# -*- coding: utf-8 -*-

from __future__ import absolute_import
"""Define routes between URL paths and views/endpoints."""

from django.conf.urls import url, include
from __future__ import (
absolute_import,
division,
print_function,
unicode_literals,
)

from django.conf import settings
from django.conf.urls import include, url
from rest_framework import routers

from readthedocs.constants import pattern_opts
from readthedocs.restapi import views
from readthedocs.restapi.views import (
core_views, footer_views, search_views, task_views, integrations
core_views,
footer_views,
integrations,
search_views,
task_views,
)

from .views.model_views import (BuildViewSet, BuildCommandViewSet,
ProjectViewSet, NotificationViewSet,
VersionViewSet, DomainViewSet,
RemoteOrganizationViewSet,
RemoteRepositoryViewSet,
SocialAccountViewSet)
from .views.model_views import (
BuildCommandViewSet,
BuildViewSet,
DomainViewSet,
NotificationViewSet,
ProjectViewSet,
RemoteOrganizationViewSet,
RemoteRepositoryViewSet,
SocialAccountViewSet,
VersionViewSet,
)

router = routers.DefaultRouter()
router.register(r'build', BuildViewSet, base_name='build')
Expand All @@ -27,11 +43,20 @@
router.register(r'notification', NotificationViewSet, base_name='emailhook')
router.register(r'domain', DomainViewSet, base_name='domain')
router.register(
r'remote/org', RemoteOrganizationViewSet, base_name='remoteorganization')
r'remote/org',
RemoteOrganizationViewSet,
base_name='remoteorganization',
)
router.register(
r'remote/repo', RemoteRepositoryViewSet, base_name='remoterepository')
r'remote/repo',
RemoteRepositoryViewSet,
base_name='remoterepository',
)
router.register(
r'remote/account', SocialAccountViewSet, base_name='remoteaccount')
r'remote/account',
SocialAccountViewSet,
base_name='remoteaccount',
)

urlpatterns = [
url(r'^', include(router.urls)),
Expand All @@ -45,65 +70,90 @@
]

search_urls = [
url(r'index_search/',
url(
r'index_search/',
search_views.index_search,
name='index_search'),
name='index_search',
),
url(r'search/$', views.search_views.search, name='api_search'),
url(r'search/project/$',
url(
r'search/project/$',
search_views.project_search,
name='api_project_search'),
url(r'search/section/$',
name='api_project_search',
),
url(
r'search/section/$',
search_views.section_search,
name='api_section_search'),
name='api_section_search',
),
]

task_urls = [
url(r'jobs/status/(?P<task_id>[^/]+)/',
url(
r'jobs/status/(?P<task_id>[^/]+)/',
task_views.job_status,
name='api_job_status'),
url(r'jobs/sync-remote-repositories/',
name='api_job_status',
),
url(
r'jobs/sync-remote-repositories/',
task_views.sync_remote_repositories,
name='api_sync_remote_repositories'),
name='api_sync_remote_repositories',
),
]

integration_urls = [
url(r'webhook/github/(?P<project_slug>{project_slug})/$'.format(**pattern_opts),
url(
r'webhook/github/(?P<project_slug>{project_slug})/$'
.format(**pattern_opts),
integrations.GitHubWebhookView.as_view(),
name='api_webhook_github'),
url(r'webhook/gitlab/(?P<project_slug>{project_slug})/$'.format(**pattern_opts),
name='api_webhook_github',
),
url(
r'webhook/gitlab/(?P<project_slug>{project_slug})/$'
.format(**pattern_opts),
integrations.GitLabWebhookView.as_view(),
name='api_webhook_gitlab'),
url(r'webhook/bitbucket/(?P<project_slug>{project_slug})/$'.format(**pattern_opts),
name='api_webhook_gitlab',
),
url(
r'webhook/bitbucket/(?P<project_slug>{project_slug})/$'
.format(**pattern_opts),
integrations.BitbucketWebhookView.as_view(),
name='api_webhook_bitbucket'),
url(r'webhook/generic/(?P<project_slug>{project_slug})/$'.format(**pattern_opts),
name='api_webhook_bitbucket',
),
url(
r'webhook/generic/(?P<project_slug>{project_slug})/$'
.format(**pattern_opts),
integrations.APIWebhookView.as_view(),
name='api_webhook_generic'),
url((r'webhook/(?P<project_slug>{project_slug})/'
r'(?P<integration_pk>{integer_pk})/$'.format(**pattern_opts)),
name='api_webhook_generic',
),
url(
(
r'webhook/(?P<project_slug>{project_slug})/'
r'(?P<integration_pk>{integer_pk})/$'.format(**pattern_opts)
),
integrations.WebhookView.as_view(),
name='api_webhook'),
name='api_webhook',
),
]

urlpatterns += function_urls
urlpatterns += search_urls
urlpatterns += task_urls
urlpatterns += integration_urls

try:
if 'readthedocsext.search' in settings.INSTALLED_APPS:
# pylint: disable=import-error
from readthedocsext.search.docsearch import DocSearch
api_search_urls = [
url(r'^docsearch/$', DocSearch.as_view(), name='doc_search'),
]
urlpatterns += api_search_urls
except ImportError:
pass

try:
from readthedocsext.donate.restapi.urls import urlpatterns as sustainability_urls
if 'readthedocsext.donate' in settings.INSTALLED_APPS:
# pylint: disable=import-error
from readthedocsext.donate.restapi.urls import urlpatterns \
as sustainability_urls

urlpatterns += [
url(r'^sustainability/', include(sustainability_urls)),
]
except ImportError:
pass