diff --git a/progit/api/__init__.py b/progit/api/__init__.py index a221174..ae3ca31 100644 --- a/progit/api/__init__.py +++ b/progit/api/__init__.py @@ -83,3 +83,52 @@ def api_users(): ] } ) + + +@API.route('//tags') +@API.route('//tags/') +@API.route('/fork///tags') +@API.route('/fork///tags/') +def api_project_tags(repo, username=None): + ''' + List all the tags of a project + ------------------------------ + Returns the list of all tags of the specified project. + + :: + + /api//tags + + /api/fork///tags + + Accepts GET queries only. + + Sample response: + + :: + + { + "tags": ["tag1", "tag2"] + } + + ''' + pattern = flask.request.args.get('pattern', None) + if pattern is not None and not pattern.endswith('*'): + pattern += '*' + + project = progit.lib.get_project(SESSION, repo, username) + if not project: + output = {'output': 'notok', 'error': 'Project not found'} + jsonout = flask.jsonify(output) + jsonout.status_code = 404 + return jsonout + + return flask.jsonify( + { + 'tags': [ + tag.tag + for tag in progit.lib.get_tags_of_project( + SESSION, project, pattern=pattern) + ] + } + )