[copr] master: Add the API entry to create a new build in a copr repository (ab7152c)

bkabrda at fedoraproject.org bkabrda at fedoraproject.org
Mon Feb 4 11:02:46 UTC 2013


Repository : http://git.fedorahosted.org/cgit/copr.git

On branch  : master

>---------------------------------------------------------------

commit ab7152cd0c7ecf33720df09a7bf254d7ae66fbe5
Author: Pierre-Yves Chibon <pingou at pingoured.fr>
Date:   Mon Feb 4 11:44:42 2013 +0100

    Add the API entry to create a new build in a copr repository
    
    Although this is looking fine especially since it is so close from the code in
    the normal controler, I have not tested it, so I guess it might break, future
    patch will come if so :)


>---------------------------------------------------------------

 coprs_frontend/coprs/views/api_ns/api_general.py |   35 ++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py b/coprs_frontend/coprs/views/api_ns/api_general.py
index 7c87388..4f9aae5 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -126,3 +126,38 @@ def api_coprs_by_owner(username=None):
     jsonout = flask.jsonify(output)
     jsonout.status_code = httpcode
     return jsonout
+
+
+ at api_ns.route('/coprs/detail/<username>/<coprname>/new_build/',
+    methods = ["POST"])
+ at login_required
+def copr_new_build(username, coprname):
+    form = forms.BuildForm()
+    copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
+    httpcode = 200
+    if not copr:
+        output = {'output': 'notok', 'error':
+            'Copr with name {0} does not exist.'.format(coprname)}
+        httpcode = 500
+
+    else:
+        if form.validate_on_submit() and flask.g.user.can_build_in(copr):
+            # we're checking authorization above for now
+            build = builds_logic.BuildsLogic.add(user=flask.g.user,
+                pkgs=form.pkgs.data.replace('\n', ' '), copr=copr)
+
+            if flask.g.user.proven:
+                build.memory_reqs = form.memory_reqs.data
+                build.timeout = form.timeout.data
+
+            db.session.commit()
+
+            output = {'output': 'ok', 'message':
+                'Build was added to {0}.'.format(coprname)}
+        else:
+            output = {'output': 'notok', 'error': 'Invalid request'}
+            httpcode = 500
+
+    jsonout = flask.jsonify(output)
+    jsonout.status_code = httpcode
+    return jsonout



More information about the copr-devel mailing list