| Trees | Indices | Help |
|---|
|
|
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"])
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 request_json = flask.request.json
34 clone_url = request_json["repository"]["clone_url"]
35 except KeyError:
36 return "Bad Request", 400
37 if "commits" in request_json:
38 commits = request_json["commits"]
39 else:
40 commits = []
41
42 packages = PackagesLogic.get_for_webhook_rebuild(copr_id, uuid, clone_url, commits)
43
44 for package in packages:
45 BuildsLogic.rebuild_package(package)
46
47 db.session.commit()
48
49 return "OK", 200
50
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Mon Sep 12 06:06:18 2016 | http://epydoc.sourceforge.net |