diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 3a7f96e..98b91b5 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -937,7 +937,7 @@ def add_file_to_git(repo, issue, ticketfolder, user, filename, filestream): return os.path.join('files', filename) -def update_file_in_git( +def _update_file_in_git( repo, branch, branchto, filename, content, message, user, email): ''' Update a specific file in the specified repository with the content given and commit the change under the user's name. diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index 3459e83..eb39af4 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -176,3 +176,38 @@ def clean_git(name, namespace, user, ticketuid): result = pagure.lib.git._clean_git(obj, project, folder) session.remove() return result + + +@conn.task +def update_file_in_git(name, namespace, user, branch, branchto, filename, + content, message, username, email): + session = pagure.lib.create_session() + + userobj = pagure.lib.search_user(session, username=username) + project = pagure.lib._get_project(session, namespace=namespace, name=name, + user=user, with_lock=True) + + pagure.lib.git._update_file_in_git(project, branch, branchto, filename, + content, message, userobj, email) + + session.remove() + return ret('view_commits', repo=project.name, username=user, + namespace=namespace, branchname=branchto) + + +@conn.task +def delete_branch(name, namespace, user, branchname): + session = pagure.lib.create_session() + + project = pagure.lib._get_project(session, namespace=namespace, name=name, + user=user, with_lock=True) + repo_obj = pygit2.Repository(pagure.get_repo_path(project)) + + try: + branch = repo_obj.lookup_branch(branchname) + branch.delete() + except pygit2.GitError as err: + _log.exception(err) + + session.remove() + return ret('view_repo', repo=name, namespace=namespace, username=user) diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 5e4acd5..c87e326 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -2123,8 +2123,10 @@ def edit_file(repo, branchname, filename, username=None, namespace=None): if form.validate_on_submit(): try: - pagure.lib.git.update_file_in_git( - repo, + taskid = pagure.lib.tasks.update_file_in_git.delay( + repo.name, + repo.namespace, + repo.user if repo.is_fork else None, branch=branchname, branchto=form.branch.data, filename=filename, @@ -2133,15 +2135,11 @@ def edit_file(repo, branchname, filename, username=None, namespace=None): form.commit_title.data.strip(), form.commit_message.data.strip() ), - user=flask.g.fas_user, + username=flask.g.fas_user.username, email=form.email.data, - ) - flask.flash('Changes committed') - return flask.redirect( - flask.url_for( - '.view_commits', repo=repo.name, username=username, - namespace=namespace, branchname=form.branch.data) - ) + ).id + return flask.redirect(flask.url_for( + 'wait_task', taskid=taskid)) except pagure.exceptions.PagureException as err: # pragma: no cover _log.exception(err) flask.flash('Commit could not be done', 'error') @@ -2195,16 +2193,10 @@ def delete_branch(repo, branchname, username=None, namespace=None): if branchname not in repo_obj.listall_branches(): flask.abort(404, 'Branch not found') - try: - branch = repo_obj.lookup_branch(branchname) - branch.delete() - flask.flash('Branch `%s` deleted' % branchname) - except pygit2.GitError as err: - _log.exception(err) - flask.flash('Could not delete `%s`' % branchname, 'error') - + taskid = pagure.lib.tasks.delete_branch.delay(repo, namespace, username, + branchname).id return flask.redirect(flask.url_for( - 'view_repo', repo=repo, username=username, namespace=namespace)) + 'wait_task', taskid=taskid)) @APP.route('/docs//')