Package coprs :: Package views :: Package webhooks_ns :: Module webhooks_general
[hide private]
[frames] | no frames]

Source Code for Module coprs.views.webhooks_ns.webhooks_general

 1  import flask 
 2   
 3  from coprs import db, app 
 4  from coprs import helpers 
 5   
 6  from coprs.logic.builds_logic import BuildsLogic 
 7  from coprs.logic.complex_logic import ComplexLogic 
 8  from coprs.logic.coprs_logic import CoprsLogic 
 9  from coprs.logic.packages_logic import PackagesLogic 
10   
11  from coprs.exceptions import ObjectNotFound, AccessRestricted 
12   
13  from coprs.views.webhooks_ns import webhooks_ns 
14  from coprs.views.misc import page_not_found, access_restricted 
15   
16  import logging 
17  log = logging.getLogger(__name__) 
18   
19   
20  @webhooks_ns.route("/github/<copr_id>/<uuid>/", methods=["POST"]) 
21 -def webhooks_hello(copr_id, uuid):
22 # For the documentation of the data we receive see: 23 # https://developer.github.com/v3/activity/events/types/#pushevent 24 try: 25 copr = ComplexLogic.get_copr_by_id_safe(copr_id) 26 except ObjectNotFound: 27 return page_not_found("Project does not exist") 28 29 if copr.webhook_secret != uuid: 30 return access_restricted("This webhook is not valid") 31 32 try: 33 payload = flask.request.json 34 clone_url = payload["repository"]["clone_url"] 35 except KeyError: 36 return "Bad Request", 400 37 38 packages = PackagesLogic.get_for_webhook_rebuild(copr_id, uuid, clone_url, payload) 39 40 for package in packages: 41 BuildsLogic.rebuild_package(package) 42 43 db.session.commit() 44 45 return "OK", 200
46