diff --git a/pagure/api/fork.py b/pagure/api/fork.py index 9621731..ebd01f3 100644 --- a/pagure/api/fork.py +++ b/pagure/api/fork.py @@ -305,11 +305,17 @@ def api_pull_request_merge(repo, requestid, username=None, namespace=None): :: + wait=False: { "message": "Merging queued", "taskid": "123-abcd" } + wait=True: + { + "message": "Changes merged!" + } + """ # noqa output = {} @@ -351,9 +357,13 @@ def api_pull_request_merge(repo, requestid, username=None, namespace=None): try: taskid = pagure.lib.tasks.merge_pull_request.delay( repo.name, namespace, username, requestid, - flask.g.fas_user.username) + flask.g.fas_user.username).id output = {'message': 'Merging queued', 'taskid': taskid} + + if flask.request.form.get('wait', True): + pagure.lib.tasks.get_result(taskid).get() + output = {'message': 'Changes merged!'} except pagure.exceptions.PagureException as err: raise pagure.exceptions.APIError( 400, error_code=APIERROR.ENOCODE, error=str(err)) diff --git a/pagure/api/project.py b/pagure/api/project.py index b2aaf2d..d39c4d9 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -450,17 +450,29 @@ def api_new_project(): | | | | projects, confirm this | | | | | with your administrators| +------------------+---------+--------------+---------------------------+ + | ``wait`` | boolean | Optional | | A boolean to specify if | + | | | | this API call should | + | | | | return a taskid or if it| + | | | | should wait for the task| + | | | | to finish. | + +------------------+---------+--------------+---------------------------+ Sample response ^^^^^^^^^^^^^^^ :: + wait=False: { 'message': 'Project creation queued', 'taskid': '123-abcd' } + wait=True: + { + 'message': 'Project creation queued' + } + """ user = pagure.lib.search_user(SESSION, username=flask.g.fas_user.username) output = {} @@ -515,6 +527,13 @@ def api_new_project(): SESSION.commit() output = {'message': 'Project creation queued', 'taskid': taskid} + + if flask.request.form.get('wait', True): + result = pagure.lib.tasks.get_result(taskid).get() + project = pagure.lib._get_project( + SESSION, name=result['repo'], + namespace=result['namespace']) + output = {'message': 'Project "%s" created' % project.fullname} except pagure.exceptions.PagureException as err: raise pagure.exceptions.APIError( 400, error_code=APIERROR.ENOCODE, error=str(err)) @@ -562,6 +581,12 @@ def api_fork_project(): | ``username`` | string | Optional | | The username of the user| | | | | of the fork. | +------------------+---------+--------------+---------------------------+ + | ``wait`` | boolean | Optional | | A boolean to specify if | + | | | | this API call should | + | | | | return a taskid or if it| + | | | | should wait for the task| + | | | | to finish. | + +------------------+---------+--------------+---------------------------+ Sample response @@ -569,11 +594,17 @@ def api_fork_project(): :: + wait=False: { "message": "Project forking queued", "taskid": "123-abcd" } + wait=True: + { + "message": 'Repo "test" cloned to "pingou/test" + } + """ output = {} @@ -602,6 +633,12 @@ def api_fork_project(): SESSION.commit() output = {'message': 'Project forking queued', 'taskid': taskid} + + if flask.request.form.get('wait', True): + pagure.lib.tasks.get_result(taskid).get() + output = {'message': 'Repo "%s" cloned to "%s/%s"' + % (repo.fullname, flask.g.fas_user.username, + repo.fullname)} except pagure.exceptions.PagureException as err: raise pagure.exceptions.APIError( 400, error_code=APIERROR.ENOCODE, error=str(err))