From 555f57e9bae071b0df0f393fa11fe23d31658383 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 29 2015 09:07:03 +0000 Subject: [PATCH 1/7] @puiterwijk was right, we do not need to import the API endpoints in the main one --- diff --git a/pagure/__init__.py b/pagure/__init__.py index 929f935..7f00dbe 100644 --- a/pagure/__init__.py +++ b/pagure/__init__.py @@ -390,9 +390,6 @@ import pagure.ui.plugins import pagure.ui.repo from pagure.api import API -from pagure.api import issue -from pagure.api import fork -from pagure.api import user APP.register_blueprint(API) import pagure.internal From a1265ee6882e9d589dc7fd8fd262b7ea0b6bf700 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 29 2015 09:07:49 +0000 Subject: [PATCH 2/7] Start work for the project controller on the API --- diff --git a/pagure/api/project.py b/pagure/api/project.py new file mode 100644 index 0000000..0d079bb --- /dev/null +++ b/pagure/api/project.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +""" + (c) 2015 - Copyright Red Hat Inc + + Authors: + Pierre-Yves Chibon + +""" + +import flask + +import pygit2 + +import pagure +import pagure.exceptions +import pagure.lib +from pagure import APP, SESSION, is_repo_admin, authenticated +from pagure.api import ( + API, api_method, api_login_required, api_login_optional, APIERROR +) + + +@API.route('//git/tags') +@API.route('/fork///git/tags') +@api_method +def api_git_tags(repo, username=None): + """ + Project git tags + ---------------- + Returns the list of tags made on the git repo of the project. + + :: + + /api/0//git/tags + /api/0/fork///git/tags + + Accepts GET queries only. + + Sample response: + + :: + + { + "tags": [], + } + + """ + repo = pagure.lib.get_project(SESSION, repo, user=username) + output = {} + + if repo is None: + raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOPROJECT) + + repopath = pagure.get_repo_path(repo) + repo_obj = pygit2.Repository(repopath) + tags = [ tag for tag in repo_obj.listall_references()] + + jsonout = flask.jsonify({'tags': tags}) + return jsonout From 0c1e005e2a87c0a131c6769ba6c142ff5199dc31 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 29 2015 09:08:43 +0000 Subject: [PATCH 3/7] Import the project API controller in the main API one --- diff --git a/pagure/api/__init__.py b/pagure/api/__init__.py index 367f4c4..eea636b 100644 --- a/pagure/api/__init__.py +++ b/pagure/api/__init__.py @@ -166,6 +166,7 @@ def api_method(function): from pagure.api import issue from pagure.api import fork +from pagure.api import project @API.route('/version/') From d7cb54b157d28d3a709acb807aeb527506b9e36e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 29 2015 09:12:53 +0000 Subject: [PATCH 4/7] Fix the api_git_tags to list only the tags, not all references --- diff --git a/pagure/api/project.py b/pagure/api/project.py index 0d079bb..83fc22b 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -54,7 +54,11 @@ def api_git_tags(repo, username=None): repopath = pagure.get_repo_path(repo) repo_obj = pygit2.Repository(repopath) - tags = [ tag for tag in repo_obj.listall_references()] + tags = [ + tag.split('refs/tags/')[1] + for tag in repo_obj.listall_references() + if 'refs/tags/' in tag + ] jsonout = flask.jsonify({'tags': tags}) return jsonout From 8289990bbf1ffba6de8401e0e9aa7b067b073425 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 29 2015 09:17:05 +0000 Subject: [PATCH 5/7] Adjust the API documentation for api_git_tags --- diff --git a/pagure/api/project.py b/pagure/api/project.py index 83fc22b..a9132d8 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -42,7 +42,7 @@ def api_git_tags(repo, username=None): :: { - "tags": [], + "tags": ["2.5.4", "2.5.5"], } """ From 1e355fcf6c55d788323ff2374507fd72d2881337 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 29 2015 09:17:19 +0000 Subject: [PATCH 6/7] Add api_git_tags to the main API documentation --- diff --git a/pagure/api/__init__.py b/pagure/api/__init__.py index eea636b..0034579 100644 --- a/pagure/api/__init__.py +++ b/pagure/api/__init__.py @@ -355,6 +355,8 @@ def api_error_codes(): @API.route('/') def api(): ''' Display the api information page. ''' + api_git_tags_doc = load_doc(project.api_git_tags) + api_new_issue_doc = load_doc(issue.api_new_issue) api_view_issues_doc = load_doc(issue.api_view_issues) @@ -373,6 +375,7 @@ def api(): return flask.render_template( 'api.html', projects=[ + api_git_tags_doc, api_new_issue_doc, api_view_issues_doc, api_pull_request_views_doc, From 04f59da0c411613f84a93a7f4a0feeaec7a8ace2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 29 2015 09:23:14 +0000 Subject: [PATCH 7/7] Move the method to retrieve the list of tags for a repo into pagure.lib.git This way we can re-use the method for the UI --- diff --git a/pagure/api/project.py b/pagure/api/project.py index a9132d8..5a3ea11 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -10,8 +10,6 @@ import flask -import pygit2 - import pagure import pagure.exceptions import pagure.lib @@ -52,13 +50,7 @@ def api_git_tags(repo, username=None): if repo is None: raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOPROJECT) - repopath = pagure.get_repo_path(repo) - repo_obj = pygit2.Repository(repopath) - tags = [ - tag.split('refs/tags/')[1] - for tag in repo_obj.listall_references() - if 'refs/tags/' in tag - ] + tags = pagure.lib.git.get_git_tags(repo) jsonout = flask.jsonify({'tags': tags}) return jsonout diff --git a/pagure/lib/git.py b/pagure/lib/git.py index c3b55ab..4ae7cbb 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -907,3 +907,17 @@ def diff_pull_request( 'Fork is empty, there are no commits to request pulling') return (diff_commits, diff) + + +def get_git_tags(project): + """ Returns the list of tags created in the git repositorie of the + specified project. + """ + repopath = pagure.get_repo_path(project) + repo_obj = pygit2.Repository(repopath) + tags = [ + tag.split('refs/tags/')[1] + for tag in repo_obj.listall_references() + if 'refs/tags/' in tag + ] + return tags