Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 7a05a7483264c3bfb6f724b883d77527764a4c73 Author: Miroslav Suchý msuchy@redhat.com Date: Tue Feb 4 10:31:15 2014 +0100
[frontend] provide info about last successfull build
coprs_frontend/coprs/logic/builds_logic.py | 19 ++++++++ coprs_frontend/coprs/logic/coprs_logic.py | 1 - coprs_frontend/coprs/templates/api.html | 54 ++++++++++++++++++++++ coprs_frontend/coprs/views/api_ns/api_general.py | 36 ++++++++++++++ 4 files changed, 109 insertions(+), 1 deletions(-)
diff --git a/coprs_frontend/coprs/logic/builds_logic.py b/coprs_frontend/coprs/logic/builds_logic.py index 4b91f29..b449ff3 100644 --- a/coprs_frontend/coprs/logic/builds_logic.py +++ b/coprs_frontend/coprs/logic/builds_logic.py @@ -162,3 +162,22 @@ class BuildsLogic(object): for build_chroot in build.build_chroots: db.session.delete(build_chroot) db.session.delete(build) + + @classmethod + def last_modified(cls, copr): + """ Get build datetime (as epoch) of last successfull build + + :arg copr: object of copr + """ + builds = cls.get_multiple(None, copr=copr) + + last_build = (builds + .join(models.BuildChroot) + .filter(models.BuildChroot.status == helpers.StatusEnum("succeeded")) + .filter(models.Build.ended_on != None) + .order_by(models.Build.ended_on.desc()) + ).first() + if last_build: + return last_build.ended_on + else: + return None diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py index 173f1d1..7cab264 100644 --- a/coprs_frontend/coprs/logic/coprs_logic.py +++ b/coprs_frontend/coprs/logic/coprs_logic.py @@ -7,7 +7,6 @@ from coprs import models from coprs import signals from coprs.logic import users_logic
- class CoprsLogic(object):
""" diff --git a/coprs_frontend/coprs/templates/api.html b/coprs_frontend/coprs/templates/api.html index 2a0a2a9..4a5a9f3 100644 --- a/coprs_frontend/coprs/templates/api.html +++ b/coprs_frontend/coprs/templates/api.html @@ -95,6 +95,60 @@ copr_url = http://copr.fedoraproject.org } </pre>
+ <h3>Detail of project</h3> + + <h4>URL:</h4> + <pre style="font-size:120%">/api/coprs/<username>/<projectname>/detail/</pre> + + <h4>URL parameters:</h4> + <ul> + <li><b>username</b> – The name of the user whose coprs you'd like + to list</li> + <li><b>priojectname</b> – The name of the project</li> + + </ul> + + <h4>Result:</h4> + <ul> + <li><b>"detial"</b> – dictionary with following keys: + <ul> + <li><b>"yum_repos"</b> – Map of chroots to yum repository + URLs. Chroots are in format + "<release>-<version>-<architecture>"</li> + <li><b>"additional_repos"</b> – List of additional + repositories that are required for this copr</li> + <li><b>"instructions"</b> – Installation instructions + provided by copr's owner </li> + <li><b>"name"</b> – Name of the copr</li> + <li><b>"description"</b> – Description provided by copr's + owner </li> + <li><b>"last_modified"</b> – Datetime (in epoch format) of + last successfull build.</li> + </ul> + </ul> + + <h4>Example call URL</h4> + <pre style="font-size:120%">https://copr.fedoraproject.org/api/coprs/jdaniels/log4j/detail/</pre> + + <h4>Example results</h4> + <pre> + { + "output": "ok", + "repos": [ + { + "yum_repos": { + "fedora-19-i686": "https://copr-be.cloud.fedoraproject.org/results/jdaniels/log4j/fedora-19-i68..." + "fedora-19-x86_64": "https://copr-be.cloud.fedoraproject.org/results/jdaniels/log4j/fedora-19-x86..." + }, + "additional_repos": "", + "instructions": "", + "name": "log4j", + "description": "Java logging package", + "last_modified": 1386695673 + } + ] + } + </pre>
<h3>Create new copr</h3>
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py b/coprs_frontend/coprs/views/api_ns/api_general.py index 166ad13..063593d 100644 --- a/coprs_frontend/coprs/views/api_ns/api_general.py +++ b/coprs_frontend/coprs/views/api_ns/api_general.py @@ -156,6 +156,42 @@ def api_coprs_by_owner(username=None): jsonout.status_code = httpcode return jsonout
+@api_ns.route("/coprs/<username>/<coprname>/detail/") +def api_coprs_by_owner_detail(username, coprname): + """ Return detail of one project. + + :arg username: the username of the person one would like to the + coprs of. + :arg coprname: the name of project. + + """ + copr = coprs_logic.CoprsLogic.get(flask.g.user, username, + coprname).first() + release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" + httpcode = 200 + if username and copr: + output = {"output": "ok", "detail": {}} + yum_repos = {} + for build in copr.builds: + if build.results: + for chroot in copr.active_chroots: + release = release_tmpl.format(chroot=chroot) + yum_repos[release] = urlparse.urljoin( + build.results, release + '/') + break + output["detail"] = {"name": copr.name, + "additional_repos": copr.repos, + "yum_repos": yum_repos, + "description": copr.description, + "instructions": copr.instructions, + "last_modified": builds_logic.BuildsLogic.last_modified(copr)} + else: + output = {"output": "notok", "error": "Copr with name {0} does not exist.".format(coprname)} + httpcode = 500 + + jsonout = flask.jsonify(output) + jsonout.status_code = httpcode + return jsonout
@api_ns.route("/coprs/<username>/<coprname>/new_build/", methods=["POST"]) @api_login_required