Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : api_search
---------------------------------------------------------------
commit 5f785d72fcfa4ee063ad8dbff759324a23cca871
Author: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
Date: Sun Feb 16 17:38:59 2014 +0400
api: implement search
Reference:
https://bugzilla.redhat.com/show_bug.cgi?id=1064118
Signed-off-by: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
---------------------------------------------------------------
coprs_frontend/coprs/templates/api.html | 49 ++++++++++++++++++++++
coprs_frontend/coprs/views/api_ns/api_general.py | 30 +++++++++++++
2 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/coprs_frontend/coprs/templates/api.html
b/coprs_frontend/coprs/templates/api.html
index e835d0f..1df4fb3 100644
--- a/coprs_frontend/coprs/templates/api.html
+++ b/coprs_frontend/coprs/templates/api.html
@@ -333,5 +333,54 @@ copr_url =
http://copr.fedoraproject.org
}
</pre>
+ <h3>Search for project</h3>
+
+ <h4>URL:</h4>
+ <pre
style="font-size:120%">/api/coprs/search/<project>/</pre>
+ <div>or</div>
+ <pre
style="font-size:120%">/api/coprs/?search="<project>"</pre>
+
+ <h4>URL parameters:</h4>
+ <ul>
+ <li><b>project</b> – The text of the project whose
you'd like
+ to find</li>
+ </ul>
+
+ <h4>Result:</h4>
+ <ul>
+ <li><b>"repos"</b> – List of repos in given
format:
+ <ul>
+ <li><b>"username"</b> – Name of the
user</li>
+ <li><b>"coprname"</b> – Name of the
copr</li>
+ <li><b>"description"</b> – Description
of the copr</li>
+ </ul>
+ </ul>
+
+ <h4>Example call URL</h4>
+ <pre
style="font-size:120%">https://copr.fedoraproject.org/api/co...
+
+ <h4>Example results</h4>
+ <pre>
+ {
+ "output": "ok",
+ "repos": [
+ {
+ "username": "ignatenkobrain",
+ "coprname": "test",
+ "description": "Tests"
+ },
+ "username": "ignatenkobrain",
+ "coprname": "tests",
+ "description": ""
+ },
+ {
+ "username": "msuchy",
+ "coprname": "tests",
+ "description": "Copr testing repository, just for test various
builds."
+ }
+ ]
+ }
+ </pre>
+
</div>
{% endblock %}
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py
b/coprs_frontend/coprs/views/api_ns/api_general.py
index 0a673d2..cc41fdd 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -340,3 +340,33 @@ def copr_chroot_details(username, coprname, chrootname):
jsonout = flask.jsonify(output)
jsonout.status_code = httpcode
return jsonout
+
+(a)api_ns.route("/coprs/search/")
+(a)api_ns.route("/coprs/search/<project>/")
+def api_coprs_search_by_project(project=None):
+ """ Return the list of coprs found in search by the given text.
+ project is taken either from GET params or from the URL itself
+ (in this order).
+
+ :arg project: the text one would like find for coprs.
+
+ """
+ project = flask.request.args.get("project", None) or project
+ httpcode = 200
+ if project:
+ query = coprs_logic.CoprsLogic.get_multiple_fulltext(
+ flask.g.user, project)
+
+ repos = query.all()
+ output = {"output": "ok", "users": []}
+ for repo in repos:
+ output["repos"].append({"username": repo.owner,
+ "coprname"; repo.name,
+ "description": repo.description})
+ else:
+ output = {"output": "notok", "error": "Invalid
request"}
+ httpcode = 500
+
+ jsonout = flask.jsonify(output)
+ jsonout.status_code = httpcode
+ return jsonout