From afcf11a0ac792a93d11cefcf6cd9f88df6a0ead4 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 06 2016 15:10:06 +0000 Subject: Install the default hook/plugin when creating a new project Adjust the unit-tests for this change --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index b4f55bb..c5d0b70 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -46,6 +46,7 @@ import pagure.exceptions import pagure.lib.git import pagure.lib.login import pagure.lib.notify +import pagure.lib.plugins import pagure.pfmarkdown from pagure.lib import model @@ -1084,6 +1085,7 @@ def new_project(session, user, name, blacklist, allowed_prefix, # Make sure we won't have SQLAlchemy error before we create the repo session.flush() + # Add the readme file if it was asked if not add_readme: pygit2.init_repository(gitrepo, bare=True) else: @@ -1107,6 +1109,7 @@ def new_project(session, user, name, blacklist, allowed_prefix, pygit2.clone_repository(temp_gitrepo_path, gitrepo, bare=True) shutil.rmtree(temp_gitrepo_path) + # Make the repo exportable via apache http_clone_file = os.path.join(gitrepo, 'git-daemon-export-ok') if not os.path.exists(http_clone_file): with open(http_clone_file, 'w') as stream: @@ -1143,6 +1146,16 @@ def new_project(session, user, name, blacklist, allowed_prefix, requestrepo, bare=True, mode=pygit2.C.GIT_REPOSITORY_INIT_SHARED_GROUP) + # Install the default hook + plugin = pagure.lib.plugins.get_plugin('default') + dbobj = plugin.db_object() + dbobj.active = True + dbobj.project_id = project.id + session.add(dbobj) + session.flush() + plugin.set_up(project) + plugin.install(project, dbobj) + # create the project in the db session.commit() diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index cb2d7ba..a34c77f 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -764,6 +764,7 @@ class PagureLibtests(tests.Modeltests): ) # Create a new project + pagure.APP.config['GIT_FOLDER'] = gitfolder msg = pagure.lib.new_project( session=self.session, user='pingou', @@ -1140,6 +1141,7 @@ class PagureLibtests(tests.Modeltests): docfolder = os.path.join(self.path, 'docs') ticketfolder = os.path.join(self.path, 'tickets') requestfolder = os.path.join(self.path, 'requests') + pagure.APP.config['GIT_FOLDER'] = gitfolder projects = pagure.lib.search_projects(self.session) self.assertEqual(len(projects), 0)