From 799be6bf4f20b98510a60f015fbdadfedf3552cf Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Apr 28 2016 18:39:18 +0000 Subject: Pass full hookname to BaseHook to simply logic. Added logger to have debug info in case of not found repo --- diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index f5afbbc..c06eb09 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -12,9 +12,13 @@ import os import shutil import wtforms import flask +import logging + from pagure import APP, get_repo_path +log = logging.getLogger(__name__) + class RequiredIf(wtforms.validators.Required): """ Wtforms validator setting a field as required if another field @@ -86,6 +90,7 @@ class BaseHook(object): for repopath in repopaths: if not os.path.exists(repopath): flask.abort(404, 'No git repo found') + log.debug('Hook install repo %s not found' % repopath) hook_files = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'files') @@ -96,12 +101,7 @@ class BaseHook(object): os.makedirs(hookfolder) # Install the hook itself - if hook_name in ['pagureforcecommit', 'pagureunsignedcommit']: - hook_file = os.path.join(repopath, 'hooks', 'pre-receive.' - + hook_name) - else: - hook_file = os.path.join(repopath, 'hooks', 'post-receive.' - + hook_name) + hook_file = os.path.join(repopath, 'hooks', hook_name) if not os.path.exists(hook_file): os.symlink( @@ -120,12 +120,8 @@ class BaseHook(object): for repopath in repopaths: if not os.path.exists(repopath): flask.abort(404, 'No git repo found') + log.debug('Hook remove repo %s not found' % repopath) - if hook_name in ['pagureforcecommit', 'pagureunsignedcommit']: - hook_path = os.path.join(repopath, 'hooks', 'pre-receive.' - + hook_name) - else: - hook_path = os.path.join(repopath, 'hooks', 'post-receive.' - + hook_name) + hook_path = os.path.join(repopath, 'hooks', hook_name) if os.path.exists(hook_path): os.unlink(hook_path) diff --git a/pagure/hooks/fedmsg.py b/pagure/hooks/fedmsg.py index c47e973..a6522b8 100644 --- a/pagure/hooks/fedmsg.py +++ b/pagure/hooks/fedmsg.py @@ -75,7 +75,7 @@ class Fedmsg(BaseHook): ''' repopaths = [get_repo_path(project)] - BaseHook.install(repopaths, dbobj, 'fedmsg', 'fedmsg_hook.py') + BaseHook.install(repopaths, dbobj, 'post-receive.fedmsg', 'fedmsg_hook.py') @classmethod def remove(cls, project): @@ -86,4 +86,4 @@ class Fedmsg(BaseHook): ''' repopaths = [get_repo_path(project)] - BaseHook.remove(repopaths, 'fedmsg') + BaseHook.remove(repopaths, 'post-receive.fedmsg') diff --git a/pagure/hooks/irc.py b/pagure/hooks/irc.py index ee6c25c..af36311 100644 --- a/pagure/hooks/irc.py +++ b/pagure/hooks/irc.py @@ -122,7 +122,7 @@ class Hook(BaseHook): # repo_obj.config.set_multivar() # Install the hook itself - # BaseHook.install(repopaths, dbobj, 'irc', 'git_irc.py') + # BaseHook.install(repopaths, dbobj, 'post-receive.irc', 'git_irc.py') @classmethod def remove(cls, project): @@ -134,4 +134,4 @@ class Hook(BaseHook): ''' repopaths = [get_repo_path(project)] - # BaseHook.remove(repopaths, 'irc') + # BaseHook.remove(repopaths, 'post-receive.irc') diff --git a/pagure/hooks/mail.py b/pagure/hooks/mail.py index 86bbece..6e688a5 100644 --- a/pagure/hooks/mail.py +++ b/pagure/hooks/mail.py @@ -93,7 +93,7 @@ class Mail(BaseHook): 'multimailhook.environment', '', 'gitolite') # Install the hook itself - BaseHook.install(repopaths, dbobj, 'mail', 'git_multimail.py') + BaseHook.install(repopaths, dbobj, 'post-receive.mail', 'git_multimail.py') @classmethod def remove(cls, project): @@ -104,4 +104,4 @@ class Mail(BaseHook): ''' repopaths = [get_repo_path(project)] - BaseHook.remove(repopaths, 'mail') + BaseHook.remove(repopaths, 'post-receive.mail') diff --git a/pagure/hooks/pagure_force_commit.py b/pagure/hooks/pagure_force_commit.py index 38fe39b..3119f9f 100644 --- a/pagure/hooks/pagure_force_commit.py +++ b/pagure/hooks/pagure_force_commit.py @@ -87,7 +87,7 @@ class PagureForceCommitHook(BaseHook): repopaths = [get_repo_path(project)] pygit2.Repository(repopaths[0]) - BaseHook.install(repopaths, dbobj, 'pagureforcecommit', + BaseHook.install(repopaths, dbobj, 'pre-receive.pagureforcecommit', 'pagure_force_commit_hook.py') @classmethod @@ -99,4 +99,4 @@ class PagureForceCommitHook(BaseHook): ''' repopaths = [get_repo_path(project)] - BaseHook.remove(repopaths, 'pagureforcecommit') + BaseHook.remove(repopaths, 'pre-receive.pagureforcecommit') diff --git a/pagure/hooks/pagure_hook.py b/pagure/hooks/pagure_hook.py index 8a7a1e4..bfadcc6 100644 --- a/pagure/hooks/pagure_hook.py +++ b/pagure/hooks/pagure_hook.py @@ -103,7 +103,8 @@ class PagureHook(BaseHook): os.path.join(folder, project.path) ) - BaseHook.install(repopaths, dbobj, 'pagure', 'pagure_hook.py') + BaseHook.install(repopaths, dbobj, 'post-receive.pagure', + 'pagure_hook.py') @classmethod def remove(cls, project): @@ -121,4 +122,4 @@ class PagureHook(BaseHook): os.path.join(folder, project.path) ) - BaseHook.remove(repopaths, 'pagure') + BaseHook.remove(repopaths, 'post-receive.pagure') diff --git a/pagure/hooks/pagure_request_hook.py b/pagure/hooks/pagure_request_hook.py index 6f89019..20f0710 100644 --- a/pagure/hooks/pagure_request_hook.py +++ b/pagure/hooks/pagure_request_hook.py @@ -102,7 +102,7 @@ class PagureRequestHook(BaseHook): ''' repopaths = [os.path.join(APP.config['REQUESTS_FOLDER'], project.path)] - BaseHook.install(repopaths, dbobj, 'pagure-requests', + BaseHook.install(repopaths, dbobj, 'post-receive.pagure-requests', 'pagure_hook_requests.py') @classmethod @@ -115,4 +115,4 @@ class PagureRequestHook(BaseHook): ''' repopaths = [os.path.join(APP.config['REQUESTS_FOLDER'], project.path)] - BaseHook.remove(repopaths, 'pagure-requests') + BaseHook.remove(repopaths, 'post-receive.pagure-requests') diff --git a/pagure/hooks/pagure_ticket_hook.py b/pagure/hooks/pagure_ticket_hook.py index 363408e..71fe780 100644 --- a/pagure/hooks/pagure_ticket_hook.py +++ b/pagure/hooks/pagure_ticket_hook.py @@ -101,7 +101,7 @@ class PagureTicketHook(BaseHook): ''' repopaths = [os.path.join(APP.config['TICKETS_FOLDER'], project.path)] - BaseHook.install(repopaths, dbobj, 'pagure-ticket', + BaseHook.install(repopaths, dbobj, 'post-receive.pagure-ticket', 'pagure_hook_tickets.py') @classmethod @@ -114,4 +114,4 @@ class PagureTicketHook(BaseHook): ''' repopaths = [os.path.join(APP.config['TICKETS_FOLDER'], project.path)] - BaseHook.remove(repopaths, 'pagure-ticket') + BaseHook.remove(repopaths, 'post-receive.pagure-ticket') diff --git a/pagure/hooks/pagure_unsigned_commits.py b/pagure/hooks/pagure_unsigned_commits.py index b57c8c3..4097edc 100644 --- a/pagure/hooks/pagure_unsigned_commits.py +++ b/pagure/hooks/pagure_unsigned_commits.py @@ -79,7 +79,7 @@ class PagureUnsignedCommitHook(BaseHook): ''' repopaths = [get_repo_path(project)] - BaseHook.install(repopaths, dbobj, 'pagureunsignedcommit', + BaseHook.install(repopaths, dbobj, 'pre-receive.pagureunsignedcommit', 'pagure_block_unsigned.py') @classmethod @@ -92,4 +92,4 @@ class PagureUnsignedCommitHook(BaseHook): ''' repopaths = [get_repo_path(project)] - BaseHook.remove(repopaths, 'pagureunsignedcommit') + BaseHook.remove(repopaths, 'pre-receive.pagureunsignedcommit') diff --git a/pagure/hooks/rtd.py b/pagure/hooks/rtd.py index 08211ce..27c2dfc 100644 --- a/pagure/hooks/rtd.py +++ b/pagure/hooks/rtd.py @@ -88,7 +88,7 @@ class RtdHook(BaseHook): ''' repopaths = [get_repo_path(project)] - BaseHook.install(repopaths, dbobj, 'rtd', 'rtd_hook.py') + BaseHook.install(repopaths, dbobj, 'post-receive.rtd', 'rtd_hook.py') @classmethod def remove(cls, project): @@ -100,4 +100,4 @@ class RtdHook(BaseHook): ''' repopaths = [get_repo_path(project)] - BaseHook.remove(repopaths, 'rtd') + BaseHook.remove(repopaths, 'post-receive.rtd')