diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 76ad42c..a48d988 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -866,15 +866,21 @@ def _add_file_to_git(repo, issue, attachmentfolder, ticketfolder, user, def _update_file_in_git( - repo, branch, branchto, filename, content, message, user, email): + repo, branch, branchto, filename, content, message, user, email, + runhook=False): ''' Update a specific file in the specified repository with the content given and commit the change under the user's name. :arg repo: the Project object from the database + :arg branch: the branch from which the edit is made + :arg branchto: the name of the branch into which to edit the file :arg filename: the name of the file to save :arg content: the new content of the file :arg message: the message of the git commit - :arg user: the user object with its username and email + :arg user: the user name, to use in the commit + :arg email: the email of the user, to use in the commit + :kwarg runhook: boolean specifying if the post-update hook should be + called or not ''' _log.info('Updating file: %s in the repo: %s', filename, repo.path) @@ -937,7 +943,7 @@ def _update_file_in_git( ) # Actually commit - new_repo.create_commit( + commit = new_repo.create_commit( nbranch_ref.name if nbranch_ref else branch_ref.name, author, author, @@ -959,6 +965,15 @@ def _update_file_in_git( raise pagure.exceptions.PagureException( 'Commit could not be done: %s' % err) + if runhook: + gitrepo_obj = PagureRepo(repopath) + gitrepo_obj.run_hook( + parent.hex, + commit.hex, + 'refs/heads/%s' % branchto, + user.username + ) + # Remove the clone shutil.rmtree(newpath) diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index 8a4c207..204ced9 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -373,7 +373,7 @@ def clean_git(name, namespace, user, ticketuid): @conn.task def update_file_in_git(name, namespace, user, branch, branchto, filename, - content, message, username, email): + content, message, username, email, runhook=False): session = pagure.lib.create_session() userobj = pagure.lib.search_user(session, username=username) @@ -384,7 +384,7 @@ def update_file_in_git(name, namespace, user, branch, branchto, filename, with project.lock('WORKER'): pagure.lib.git._update_file_in_git( project, branch, branchto, filename, - content, message, userobj, email) + content, message, userobj, email, runhook=runhook) session.remove() return ret('view_commits', repo=project.name, username=user, diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index d124f35..0329cdb 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -2220,6 +2220,7 @@ def edit_file(repo, branchname, filename, username=None, namespace=None): ), username=user.username, email=form.email.data, + runhook=True, ).id return flask.redirect(flask.url_for( 'wait_task', taskid=taskid))