From eab92f230312b5f159e57bff29c0b674cc81137b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 10 2015 16:35:15 +0000 Subject: Locally override the set_up method as this hook is on the ticket repository Thus we should check whether this ticket repository exists rather than checking for the main git repo --- diff --git a/progit/hooks/progit_ticket_hook.py b/progit/hooks/progit_ticket_hook.py index d9df854..b85b865 100644 --- a/progit/hooks/progit_ticket_hook.py +++ b/progit/hooks/progit_ticket_hook.py @@ -11,6 +11,7 @@ import os import shutil +import flask import sqlalchemy as sa import pygit2 import wtforms @@ -63,6 +64,31 @@ class ProgitTicketHook(BaseHook): form_fields = ['active'] @classmethod + def set_up(cls, project): + ''' Install the generic post-receive hook that allow us to call + multiple post-receive hooks as set per plugin. + ''' + repopath = os.path.join(APP.config['TICKETS_FOLDER'], project.path) + if not os.path.exists(repopath): + flask.abort(404, 'No git repo found') + + hook_files = os.path.join( + os.path.dirname(os.path.realpath(__file__)), 'files') + + # Make sure the hooks folder exists + hookfolder = os.path.join(repopath, 'hooks') + if not os.path.exists(hookfolder): + os.makedirs(hookfolder) + + # Install the main post-receive file + postreceive = os.path.join(hookfolder, 'post-receive') + if not os.path.exists(postreceive): + shutil.copyfile( + os.path.join(hook_files, 'post-receive'), + postreceive) + os.chmod(postreceive, 0755) + + @classmethod def install(cls, project, dbobj): ''' Method called to install the hook for a project.