From d3d4c657db3a9ea036f3a0541d4279f77ecbea74 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 26 2018 10:37:19 +0000 Subject: Name the arguments in the function call and other fixes - Close the DB session at the end of the function - Log to the terminal the project for which we're running the hooks (this way it will show up in the error email when a merge PR task fails) - Ensure there is a project, should never be triggered though Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index 4276200..b1df5d2 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -83,13 +83,31 @@ class BaseRunner(object): """ if hooktype == "pre-receive": cls.pre_receive( - session, username, project, repotype, repodir, changes + session=session, + username=username, + project=project, + repotype=repotype, + repodir=repodir, + changes=changes, ) elif hooktype == "update": - cls.update(session, username, project, repotype, repodir, changes) + cls.update( + session=session, + username=username, + project=project, + repotype=repotype, + repodir=repodir, + changes=changes, + ) + elif hooktype == "post-receive": cls.post_receive( - session, username, project, repotype, repodir, changes + session=session, + username=username, + project=project, + repotype=repotype, + repodir=repodir, + changes=changes, ) else: raise ValueError('Invalid hook type "%s"' % hooktype) @@ -339,13 +357,13 @@ def run_project_hooks( print("Running plugin %s" % plugin.name) plugin.runner.runhook( - session, - username, - hooktype, - project, - repotype, - repodir, - changes, + session=session, + username=username, + hooktype=hooktype, + project=project, + repotype=repotype, + repodir=repodir, + changes=changes, ) if project.is_on_repospanner: @@ -465,7 +483,13 @@ def run_hook_file(hooktype): project = pagure.lib._get_project( session, repo, user=username, namespace=namespace ) + if not project: + raise Exception( + "Not able to find the project corresponding to: %%s - s - " + "%s - %s" % (repotype, username, namespace, repo) + ) + print("Running hooks for %s" % project.fullname) run_project_hooks( session, pushuser, @@ -477,3 +501,4 @@ def run_hook_file(hooktype): is_internal, pull_request, ) + session.close()