Commit ec938c30 authored by Michal Čihař's avatar Michal Čihař

Add API to commit pending

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 6e282062
......@@ -293,6 +293,27 @@ BITBUCKET_PAYLOAD_WEBHOOK = r'''
class HooksViewTest(ViewTestCase):
@OverrideSettings(ENABLE_HOOKS=True)
@OverrideSettings(BACKGROUND_HOOKS=False)
def test_view_commit_hook_project(self):
response = self.client.get(
reverse('hook-commit-project', kwargs={
'project': self.subproject.project.slug
})
)
self.assertContains(response, 'Commit performed')
@OverrideSettings(ENABLE_HOOKS=True)
@OverrideSettings(BACKGROUND_HOOKS=False)
def test_view_commit_hook_subproject(self):
response = self.client.get(
reverse('hook-commit-subproject', kwargs={
'project': self.subproject.project.slug,
'subproject': self.subproject.slug,
})
)
self.assertContains(response, 'Commit performed')
@OverrideSettings(ENABLE_HOOKS=True)
@OverrideSettings(BACKGROUND_HOOKS=False)
def test_view_hook_project(self):
......
......@@ -70,10 +70,10 @@ GITHUB_REPOS = (
HOOK_HANDLERS = {}
def hook_response():
def hook_response(response='Update triggered'):
"""Generic okay hook response"""
return JsonResponse(
data={'status': 'success', 'message': 'Update triggered'},
data={'status': 'success', 'message': response},
)
......@@ -97,6 +97,34 @@ def perform_update(obj):
obj.do_update()
@csrf_exempt
def commit_subproject(request, project, subproject):
'''
API hook for updating git repos.
'''
if not appsettings.ENABLE_HOOKS:
return HttpResponseNotAllowed([])
obj = get_subproject(request, project, subproject, True)
if not obj.project.enable_hooks:
return HttpResponseNotAllowed([])
obj.commit_pending(None)
return hook_response('Commit performed')
@csrf_exempt
def commit_project(request, project):
'''
API hook for updating git repos.
'''
if not appsettings.ENABLE_HOOKS:
return HttpResponseNotAllowed([])
obj = get_project(request, project, True)
if not obj.enable_hooks:
return HttpResponseNotAllowed([])
obj.commit_pending(None)
return hook_response('Commit performed')
@csrf_exempt
def update_subproject(request, project, subproject):
'''
......
......@@ -472,6 +472,16 @@ urlpatterns = [
weblate.trans.views.api.update_project,
name='hook-project',
),
url(
r'^hooks/commit/' + SUBPROJECT + '$',
weblate.trans.views.api.commit_subproject,
name='hook-commit-subproject',
),
url(
r'^hooks/commit/' + PROJECT + '$',
weblate.trans.views.api.commit_project,
name='hook-commit-project',
),
url(
r'^hooks/github/$', weblate.trans.views.api.vcs_service_hook,
{'service': 'github'},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment