From adea204dd0e86891d7e015ef05e57dae4ec5c3f9 Mon Sep 17 00:00:00 2001 From: Slavek Kabrda Date: Feb 27 2018 09:22:20 +0000 Subject: Disable setting folders for docs, requests and tickets. Fixes #2991 --- diff --git a/README.rst b/README.rst index 5bc6ee0..538c198 100644 --- a/README.rst +++ b/README.rst @@ -119,7 +119,7 @@ Manually * Create the folder that will receive the projects, forks, docs, requests and tickets' git repo:: - mkdir -p lcl/{repos,docs,forks,tickets,requests,remotes,attachments,releases} + mkdir -p lcl/{repos,remotes,attachments,releases} * Copy and edit the alembic.ini file (especially the ``script_location`` key):: diff --git a/dev/ansible/roles/pagure-dev/files/pagure.cfg b/dev/ansible/roles/pagure-dev/files/pagure.cfg index a813f09..94780d3 100644 --- a/dev/ansible/roles/pagure-dev/files/pagure.cfg +++ b/dev/ansible/roles/pagure-dev/files/pagure.cfg @@ -8,6 +8,10 @@ from datetime import timedelta # (ie: changing a project's or a user's settings) ADMIN_SESSION_LIFETIME = timedelta(minutes=20000000) +# Enable tickets and docs for all repos +ENABLE_TICKETS = True +ENABLE_DOCS = True + ### Secret key for the Flask application SECRET_KEY='' @@ -42,15 +46,6 @@ STORAGE_ROOT = '/home/vagrant/pagure_data/' GIT_FOLDER = os.path.join(STORAGE_ROOT, 'repos') -### Folder containing the docs repos -DOCS_FOLDER = os.path.join(STORAGE_ROOT, 'docs') - -### Folder containing the tickets repos -TICKETS_FOLDER = os.path.join(STORAGE_ROOT, 'tickets') - -### Folder containing the pull-requests repos -REQUESTS_FOLDER = os.path.join(STORAGE_ROOT, 'requests') - ### Folder containing the clones for the remote pull-requests REMOTE_GIT_FOLDER = os.path.join(STORAGE_ROOT, 'remotes') diff --git a/dev/openshift.cfg b/dev/openshift.cfg index 420aee2..bb2ee63 100644 --- a/dev/openshift.cfg +++ b/dev/openshift.cfg @@ -1,3 +1,5 @@ +ENABLE_TICKETS = True +ENABLE_DOCS = True SECRET_KEY = 'klalkdsaskrhjklh3423423' DB_URL = 'postgresql://pagure:pagure@postgresql/pagure' INSTANCE_NAME = 'DEVELOPMENT PAGURE' @@ -5,9 +7,6 @@ EMAIL_ERROR = '' APP_URL = 'http://localhost:5000/' REDIS_HOST = 'redis' GIT_FOLDER = '/repos/repos' -DOCS_FOLDER = '/repos/docs' -TICKETS_FOLDER = '/repos/tickets' -REQUESTS_FOLDER = '/repos/requests' REMOTE_GIT_FOLDER = '/repos/remote' ATTACHMENTS_FOLDER = '/attachments' EVENTSOURCE_SOURCE = 'http://localhost:8080' diff --git a/doc/configuration.rst b/doc/configuration.rst index 92e9afd..32fece0 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -110,11 +110,12 @@ Defaults to: ``'redis://%s' % APP.config['REDIS_HOST']`` Repo Directories ---------------- -Each project in pagure has 4 git repositories: +Each project in pagure has 2 to 4 git repositories, depending on configuration +of the Pagure instance (see below): - the main repo for the code -- the doc repo showed in the doc server -- the ticket repo storing the metadata of the tickets +- the doc repo showed in the doc server (optional) +- the ticket repo storing the metadata of the tickets (optional) - the request repo storing the metadata of the pull-requests There are then another 3 folders: one for specifying the locations of the forks, one @@ -125,29 +126,19 @@ a project not hosted on this instance of pagure), and one for user-uploaded tarb GIT_FOLDER ~~~~~~~~~~ -This configuration key points to the folder where the git repos for the -source code of the projects are stored. +This configuration key points to the folder where the git repos are stored. +For every project, two to four repos are created: +* a repo with source code of the project +* a repo with documentation of the project + (if ``ENABLE_DOCS`` is ``True``) +* a repo with metadata of tickets opened against the project + (if ``ENABLE_TICKETS`` is ``True``) +* a repo with metadata of pull requests opened against the project -DOCS_FOLDER -~~~~~~~~~~~ - -This configuration key points to the folder where the git repos for the -documentation of the projects are stored. - - -TICKETS_FOLDER -~~~~~~~~~~~~~~ - -This configuration key points to the folder where the git repos for the -metadata of the tickets opened against the project are stored . - - -REQUESTS_FOLDER -~~~~~~~~~~~~~~~ - -This configuration key points to the folder where the git repos for the -metadata of the pull-requests opened against the project are stored. +Note that gitolite config value ``GL_REPO_BASE`` (if using gitolite 3) +or ``$REPO_BASE`` (if using gitolite 2) **must** have exactly the same +value as ``GIT_FOLDER``. REMOTE_GIT_FOLDER @@ -687,6 +678,15 @@ for all the projects hosted on this pagure instance. Defaults to: ``True`` +ENABLE_DOCS +~~~~~~~~~~~ + +This configuration key activates or deactivates creation of git repos +for documentation for all the projects hosted on this pagure instance. + +Defaults to: ``True`` + + ENABLE_NEW_PROJECTS ~~~~~~~~~~~~~~~~~~~ @@ -1069,3 +1069,14 @@ using, it can be either ``2`` or ``3``. Defaults to: ``3``. This has been replaced by `GITOLITE_BACKEND` in the release 3.0 of pagure. + +DOCS_FOLDER, REQUESTS_FOLDER, TICKETS_FOLDER +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +These configuration values were removed. It has been found out that +due to how Pagure writes repo names in the gitolite configuration file, +these must have fixed paths relative to `GIT_FOLDER`. Specifically, they +must occupy subdirectories `docs`, `requests` and `tickets` under `GIT_FOLDER`. +They are now computed automatically based on value of `GIT_FOLDER`. +Usage of docs and tickets can be triggered by setting `ENABLE_DOCS` and +`ENABLE_TICKETS` to `True` (this is the default). diff --git a/files/gitolite3.rc b/files/gitolite3.rc index 1a20d42..2754ed7 100644 --- a/files/gitolite3.rc +++ b/files/gitolite3.rc @@ -16,6 +16,8 @@ # ------------------------------------------------------------------ + GL_REPO_BASE => '/srv/git/repositories' + # default umask gives you perms of '0700'; see the rc file docs for # how/why you might change this UMASK => 0077, diff --git a/files/pagure.cfg.sample b/files/pagure.cfg.sample index 46b0fee..6a919f6 100644 --- a/files/pagure.cfg.sample +++ b/files/pagure.cfg.sample @@ -8,6 +8,10 @@ from datetime import timedelta # (ie: changing a project's or a user's settings) ADMIN_SESSION_LIFETIME = timedelta(minutes=20) +# Enable tickets and docs for all repos +ENABLE_TICKETS = True +ENABLE_DOCS = True + ### Secret key for the Flask application SECRET_KEY='' @@ -57,27 +61,6 @@ GIT_FOLDER = os.path.join( 'repos' ) -### Folder containing the docs repos -DOCS_FOLDER = os.path.join( - os.path.abspath(os.path.dirname(__file__)), - '..', - 'docs' -) - -### Folder containing the tickets repos -TICKETS_FOLDER = os.path.join( - os.path.abspath(os.path.dirname(__file__)), - '..', - 'tickets' -) - -### Folder containing the pull-requests repos -REQUESTS_FOLDER = os.path.join( - os.path.abspath(os.path.dirname(__file__)), - '..', - 'requests' -) - ### Folder containing the clones for the remote pull-requests REMOTE_GIT_FOLDER = os.path.join( os.path.abspath(os.path.dirname(__file__)), diff --git a/pagure/config.py b/pagure/config.py index da043ce..3347949 100644 --- a/pagure/config.py +++ b/pagure/config.py @@ -24,6 +24,26 @@ def reload_config(): if 'PAGURE_CONFIG' in os.environ: config.from_envvar('PAGURE_CONFIG') + # These were previously respected config values, but as explained + # in https://pagure.io/pagure/issue/2991 they don't really work + # as expected and their values must be based on GIT_FOLDER. + # To prevent large changes throughout the codebase, we omitted them + # from config and we add them here. + if config['ENABLE_DOCS']: + config['DOCS_FOLDER'] = os.path.join( + config['GIT_FOLDER'], + 'docs' + ) + if config['ENABLE_TICKETS']: + config['TICKETS_FOLDER'] = os.path.join( + config['GIT_FOLDER'], + 'tickets' + ) + config['REQUESTS_FOLDER'] = os.path.join( + config['GIT_FOLDER'], + 'requests' + ) + return config diff --git a/pagure/default_config.py b/pagure/default_config.py index 7c74374..18c179f 100644 --- a/pagure/default_config.py +++ b/pagure/default_config.py @@ -47,6 +47,9 @@ APP_URL = 'https://pagure.org/' # Enables / Disables tickets for project for the entire pagure instance ENABLE_TICKETS = True +# Enables / Disables docs for project for the entire pagure instance +ENABLE_DOCS = True + # Enables / Disables creating projects on this pagure instance ENABLE_NEW_PROJECTS = True @@ -103,6 +106,7 @@ REDIS_DB = 0 EVENTSOURCE_PORT = 8080 # Folder containing to the git repos +# Note that this must be exactly the same as GL_REPO_BASE in gitolite.rc GIT_FOLDER = os.path.join( os.path.abspath(os.path.dirname(__file__)), '..', @@ -110,30 +114,6 @@ GIT_FOLDER = os.path.join( 'repos' ) -# Folder containing the docs repos -DOCS_FOLDER = os.path.join( - os.path.abspath(os.path.dirname(__file__)), - '..', - 'lcl', - 'docs' -) - -# Folder containing the tickets repos -TICKETS_FOLDER = os.path.join( - os.path.abspath(os.path.dirname(__file__)), - '..', - 'lcl', - 'tickets' -) - -# Folder containing the pull-requests repos -REQUESTS_FOLDER = os.path.join( - os.path.abspath(os.path.dirname(__file__)), - '..', - 'lcl', - 'requests' -) - # Folder containing the clones for the remote pull-requests REMOTE_GIT_FOLDER = os.path.join( os.path.abspath(os.path.dirname(__file__)), @@ -259,7 +239,7 @@ BLACKLISTED_PROJECTS = [ 'static', 'pv', 'releases', 'new', 'api', 'settings', 'search', 'fork', 'logout', 'login', 'user', 'users', 'groups', 'projects', 'ssh_info', 'issues', 'pull-requests', 'commits', 'tree', 'forks', 'admin', 'c', - 'wait', + 'wait', 'docs/*, tickets/*, requests/*' ] # List of prefix allowed in project names diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 1bfda0a..cc657b5 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -23,6 +23,7 @@ except ImportError: # pragma: no cover import datetime import fnmatch +import functools import hashlib import logging import os @@ -1477,11 +1478,12 @@ def new_project(session, user, name, blacklist, allowed_prefix, Is an async operation, and returns task ID. ''' - if (not namespace and name in blacklist) \ - or (namespace and '%s/%s' % (namespace, name) in blacklist): + ns_name = name if not namespace else '%s/%s' % (namespace, name) + matched = any(map(functools.partial(fnmatch.fnmatch, ns_name), blacklist)) + if matched: raise pagure.exceptions.ProjectBlackListedException( 'No project "%s" are allowed to be created due to potential ' - 'conflicts in URLs with pagure itself' % name + 'conflicts in URLs with pagure itself' % ns_name ) user_obj = get_user(session, user) diff --git a/tests/__init__.py b/tests/__init__.py index ca88171..1cf6d16 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -64,9 +64,8 @@ PAGLOG.handlers = [] CONFIG_TEMPLATE = """ GIT_FOLDER = '%(path)s/repos' -DOCS_FOLDER = '%(path)s/docs' -TICKETS_FOLDER = '%(path)s/tickets' -REQUESTS_FOLDER = '%(path)s/requests' +ENABLE_DOCS = True +ENABLE_TICKETS = True REMOTE_GIT_FOLDER = '%(path)s/remotes' ATTACHMENTS_FOLDER = '%(path)s/attachments' DB_URL = '%(dburl)s' @@ -238,8 +237,7 @@ class SimplePagureTest(unittest.TestCase): raise Exception('Double init?!') self.path = tempfile.mkdtemp(prefix='pagure-tests-path-') LOG.debug('Testdir: %s', self.path) - for folder in ['tickets', 'repos', 'forks', 'docs', 'requests', - 'releases', 'remotes', 'attachments']: + for folder in ['repos', 'forks', 'releases', 'remotes', 'attachments']: os.mkdir(os.path.join(self.path, folder)) if DB_PATH: @@ -258,14 +256,14 @@ class SimplePagureTest(unittest.TestCase): # Prevent unit-tests to send email, globally pagure_config['EMAIL_SEND'] = False pagure_config['TESTING'] = True - pagure_config['GIT_FOLDER'] = os.path.join( + pagure_config['GIT_FOLDER'] = gf = os.path.join( self.path, 'repos') pagure_config['TICKETS_FOLDER'] = os.path.join( - self.path, 'tickets') + gf, 'tickets') pagure_config['DOCS_FOLDER'] = os.path.join( - self.path, 'docs') + gf, 'docs') pagure_config['REQUESTS_FOLDER'] = os.path.join( - self.path, 'requests') + gf, 'requests') pagure_config['ATTACHMENTS_FOLDER'] = os.path.join( self.path, 'attachments') diff --git a/tests/test_pagure_flask_dump_load_ticket.py b/tests/test_pagure_flask_dump_load_ticket.py index 1265773..83de075 100644 --- a/tests/test_pagure_flask_dump_load_ticket.py +++ b/tests/test_pagure_flask_dump_load_ticket.py @@ -45,8 +45,8 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests): tests.create_projects(self.session) # Create repo - self.gitrepo = os.path.join(self.path, 'tickets', 'test.git') - repopath = os.path.join(self.path, 'tickets') + self.gitrepo = os.path.join(self.path, 'repos', 'tickets', 'test.git') + repopath = os.path.join(self.path, 'repos', 'tickets') os.makedirs(self.gitrepo) repo_obj = pygit2.init_repository(self.gitrepo, bare=True) diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index 21a7fcc..4f3e56c 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -205,11 +205,11 @@ class PagureFlaskApptests(tests.Modeltests): self.assertFalse(os.path.exists( os.path.join(self.path, 'repos', 'project-1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'tickets', 'project-1.git'))) + os.path.join(self.path, 'repos', 'tickets', 'project-1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'docs', 'project-1.git'))) + os.path.join(self.path, 'repos', 'docs', 'project-1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'requests', 'project-1.git'))) + os.path.join(self.path, 'repos', 'requests', 'project-1.git'))) user = tests.FakeUser() with tests.user_set(self.app.application, user): @@ -241,11 +241,11 @@ class PagureFlaskApptests(tests.Modeltests): self.assertFalse(os.path.exists( os.path.join(self.path, 'repos', 'project-1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'tickets', 'project-1.git'))) + os.path.join(self.path, 'repos', 'tickets', 'project-1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'docs', 'project-1.git'))) + os.path.join(self.path, 'repos', 'docs', 'project-1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'requests', 'project-1.git'))) + os.path.join(self.path, 'repos', 'requests', 'project-1.git'))) pagure.config.config['ENABLE_NEW_PROJECTS'] = True @@ -257,11 +257,11 @@ class PagureFlaskApptests(tests.Modeltests): self.assertFalse(os.path.exists( os.path.join(self.path, 'repos', 'project#1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'tickets', 'project#1.git'))) + os.path.join(self.path, 'repos', 'tickets', 'project#1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'docs', 'project#1.git'))) + os.path.join(self.path, 'repos', 'docs', 'project#1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'requests', 'project#1.git'))) + os.path.join(self.path, 'repos', 'requests', 'project#1.git'))) user = tests.FakeUser() with tests.user_set(self.app.application, user): @@ -320,11 +320,11 @@ class PagureFlaskApptests(tests.Modeltests): self.assertTrue(os.path.exists( os.path.join(self.path, 'repos', 'project-1.git'))) self.assertTrue(os.path.exists( - os.path.join(self.path, 'tickets', 'project-1.git'))) + os.path.join(self.path, 'repos', 'tickets', 'project-1.git'))) self.assertTrue(os.path.exists( - os.path.join(self.path, 'docs', 'project-1.git'))) + os.path.join(self.path, 'repos', 'docs', 'project-1.git'))) self.assertTrue(os.path.exists( - os.path.join(self.path, 'requests', 'project-1.git'))) + os.path.join(self.path, 'repos', 'requests', 'project-1.git'))) @patch.dict('pagure.config.config', {'PROJECT_NAME_REGEX': '^1[a-z]*$'}) def test_new_project_diff_regex(self): @@ -367,11 +367,11 @@ class PagureFlaskApptests(tests.Modeltests): self.assertFalse(os.path.exists( os.path.join(self.path, 'repos', 'foo', 'project#1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'tickets', 'foo', 'project#1.git'))) + os.path.join(self.path, 'repos', 'tickets', 'foo', 'project#1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'docs', 'foo', 'project#1.git'))) + os.path.join(self.path, 'repos', 'docs', 'foo', 'project#1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'requests', 'foo', 'project#1.git'))) + os.path.join(self.path, 'repos', 'requests', 'foo', 'project#1.git'))) user = tests.FakeUser() with tests.user_set(self.app.application, user): @@ -433,11 +433,11 @@ class PagureFlaskApptests(tests.Modeltests): self.assertTrue(os.path.exists( os.path.join(self.path, 'repos', 'foo', 'project-1.git'))) self.assertTrue(os.path.exists( - os.path.join(self.path, 'tickets', 'foo', 'project-1.git'))) + os.path.join(self.path, 'repos', 'tickets', 'foo', 'project-1.git'))) self.assertTrue(os.path.exists( - os.path.join(self.path, 'docs', 'foo', 'project-1.git'))) + os.path.join(self.path, 'repos', 'docs', 'foo', 'project-1.git'))) self.assertTrue(os.path.exists( - os.path.join(self.path, 'requests', 'foo', 'project-1.git'))) + os.path.join(self.path, 'repos', 'requests', 'foo', 'project-1.git'))) def test_non_ascii_new_project(self): """ Test the new_project endpoint with a non-ascii project. """ @@ -447,11 +447,11 @@ class PagureFlaskApptests(tests.Modeltests): self.assertFalse(os.path.exists( os.path.join(self.path, 'repos', 'project-1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'tickets', 'project-1.git'))) + os.path.join(self.path, 'repos', 'tickets', 'project-1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'docs', 'project-1.git'))) + os.path.join(self.path, 'repos', 'docs', 'project-1.git'))) self.assertFalse(os.path.exists( - os.path.join(self.path, 'requests', 'project-1.git'))) + os.path.join(self.path, 'repos', 'requests', 'project-1.git'))) user = tests.FakeUser() user.username = 'foo' @@ -505,11 +505,11 @@ class PagureFlaskApptests(tests.Modeltests): self.assertTrue(os.path.exists( os.path.join(self.path, 'repos', '%s.git' % project))) self.assertTrue(os.path.exists( - os.path.join(self.path, 'tickets', '%s.git' % project))) + os.path.join(self.path, 'repos', 'tickets', '%s.git' % project))) self.assertTrue(os.path.exists( - os.path.join(self.path, 'docs', '%s.git' % project))) + os.path.join(self.path, 'repos', 'docs', '%s.git' % project))) self.assertTrue(os.path.exists( - os.path.join(self.path, 'requests', '%s.git' % project))) + os.path.join(self.path, 'repos', 'requests', '%s.git' % project))) @patch('pagure.ui.app.admin_session_timedout') def test_user_settings(self, ast): diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py index 92cf4ff..84e94b8 100644 --- a/tests/test_pagure_flask_ui_issues.py +++ b/tests/test_pagure_flask_ui_issues.py @@ -2222,7 +2222,7 @@ class PagureFlaskIssuestests(tests.Modeltests): tests.create_projects_git( os.path.join(self.path, 'repos'), bare=True) tests.create_projects_git( - os.path.join(self.path, 'tickets'), bare=True) + os.path.join(self.path, 'repos', 'tickets'), bare=True) # Create issues to play with repo = pagure.lib.get_authorized_project(self.session, 'test') diff --git a/tests/test_pagure_flask_ui_plugins_fedmsg.py b/tests/test_pagure_flask_ui_plugins_fedmsg.py index 67c0532..4c7130d 100644 --- a/tests/test_pagure_flask_ui_plugins_fedmsg.py +++ b/tests/test_pagure_flask_ui_plugins_fedmsg.py @@ -149,7 +149,7 @@ class PagureFlaskPluginFedmsgtests(tests.SimplePagureTest): self.path, 'repos', 'test.git', 'hooks', 'post-receive.fedmsg'))) self.assertTrue(os.path.exists(os.path.join( - self.path, 'docs', 'test.git', 'hooks', + self.path, 'repos', 'docs', 'test.git', 'hooks', 'post-receive'))) def test_plugin_fedmsg_deactivate(self): @@ -187,7 +187,7 @@ class PagureFlaskPluginFedmsgtests(tests.SimplePagureTest): self.path, 'repos', 'test.git', 'hooks', 'post-receive.fedmsg'))) self.assertTrue(os.path.exists(os.path.join( - self.path, 'docs', 'test.git', 'hooks', + self.path, 'repos', 'docs', 'test.git', 'hooks', 'post-receive'))) @patch.dict('pagure.config.config', {'DOCS_FOLDER': None}) diff --git a/tests/test_pagure_flask_ui_plugins_pagure_hook.py b/tests/test_pagure_flask_ui_plugins_pagure_hook.py index c882370..2af3779 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_hook.py @@ -36,7 +36,7 @@ class PagureFlaskPluginPagureHooktests(tests.SimplePagureTest): tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'repos')) - tests.create_projects_git(os.path.join(self.path, 'docs')) + tests.create_projects_git(os.path.join(self.path, 'repos', 'docs')) def test_plugin_mail_page(self): """ Test the default page of the pagure hook plugin. """ @@ -89,8 +89,8 @@ class PagureFlaskPluginPagureHooktests(tests.SimplePagureTest): data = {'csrf_token': csrf_token} - tests.create_projects_git(os.path.join(self.path, 'docs')) - tests.create_projects_git(os.path.join(self.path, 'requests')) + tests.create_projects_git(os.path.join(self.path, 'repos', 'docs')) + tests.create_projects_git(os.path.join(self.path, 'repos', 'requests')) # With the git repo output = self.app.post( @@ -164,7 +164,7 @@ class PagureFlaskPluginPagureHooktests(tests.SimplePagureTest): self.path, 'repos', 'test.git', 'hooks', 'post-receive'))) self.assertTrue(os.path.exists(os.path.join( - self.path, 'docs', 'test.git', 'hooks', + self.path, 'repos', 'docs', 'test.git', 'hooks', 'post-receive'))) def test_plugin_mail_deactivate_hook(self): @@ -205,7 +205,7 @@ class PagureFlaskPluginPagureHooktests(tests.SimplePagureTest): self.path, 'repos', 'test.git', 'hooks', 'post-receive'))) self.assertTrue(os.path.exists(os.path.join( - self.path, 'docs', 'test.git', 'hooks', + self.path, 'repos', 'docs', 'test.git', 'hooks', 'post-receive'))) @patch.dict('pagure.config.config', {'DOCS_FOLDER': None}) diff --git a/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py b/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py index 1f5089e..f562221 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py @@ -66,7 +66,7 @@ class PagureFlaskPluginPagureRequestHooktests(tests.SimplePagureTest): data['csrf_token'] = csrf_token # Create the requests repo - tests.create_projects_git(os.path.join(self.path, 'requests')) + tests.create_projects_git(os.path.join(self.path, 'repos', 'requests')) output = self.app.post( '/test/settings/Pagure requests', data=data, @@ -121,7 +121,7 @@ class PagureFlaskPluginPagureRequestHooktests(tests.SimplePagureTest): 'value="y">' in output.data) self.assertTrue(os.path.exists(os.path.join( - self.path, 'requests', 'test.git', 'hooks', + self.path, 'repos', 'requests', 'test.git', 'hooks', 'post-receive.pagure-requests'))) # De-Activate hook @@ -156,7 +156,7 @@ class PagureFlaskPluginPagureRequestHooktests(tests.SimplePagureTest): 'csrf_token': csrf_token, 'active': 'y', } - shutil.rmtree(os.path.join(self.path, 'requests', 'test.git')) + shutil.rmtree(os.path.join(self.path, 'repos', 'requests', 'test.git')) output = self.app.post('/test/settings/Pagure requests', data=data) self.assertEqual(output.status_code, 404) diff --git a/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py b/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py index eba24f1..4482912 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py @@ -66,7 +66,7 @@ class PagureFlaskPluginPagureTicketHooktests(tests.SimplePagureTest): data['csrf_token'] = csrf_token # Create the tickets repo - tests.create_projects_git(os.path.join(self.path, 'tickets')) + tests.create_projects_git(os.path.join(self.path, 'repos', 'tickets')) output = self.app.post( '/test/settings/Pagure tickets', data=data, @@ -121,7 +121,7 @@ class PagureFlaskPluginPagureTicketHooktests(tests.SimplePagureTest): 'value="y">' in output.data) self.assertTrue(os.path.exists(os.path.join( - self.path, 'tickets', 'test.git', 'hooks', + self.path, 'repos', 'tickets', 'test.git', 'hooks', 'post-receive.pagure-ticket'))) # De-Activate hook @@ -156,7 +156,7 @@ class PagureFlaskPluginPagureTicketHooktests(tests.SimplePagureTest): 'csrf_token': csrf_token, 'active': 'y', } - shutil.rmtree(os.path.join(self.path, 'tickets', 'test.git')) + shutil.rmtree(os.path.join(self.path, 'repos', 'tickets', 'test.git')) output = self.app.post('/test/settings/Pagure tickets', data=data) self.assertEqual(output.status_code, 404) diff --git a/tests/test_pagure_flask_ui_repo_delete_project.py b/tests/test_pagure_flask_ui_repo_delete_project.py index 0301aab..7eaecf4 100644 --- a/tests/test_pagure_flask_ui_repo_delete_project.py +++ b/tests/test_pagure_flask_ui_repo_delete_project.py @@ -38,11 +38,11 @@ class PagureFlaskDeleteRepotests(tests.Modeltests): # Create all the git repos tests.create_projects_git(os.path.join(self.path, 'repos')) - tests.create_projects_git(os.path.join(self.path, 'docs')) + tests.create_projects_git(os.path.join(self.path, 'repos', 'docs')) tests.create_projects_git( - os.path.join(self.path, 'tickets'), bare=True) + os.path.join(self.path, 'repos', 'tickets'), bare=True) tests.create_projects_git( - os.path.join(self.path, 'requests'), bare=True) + os.path.join(self.path, 'repos', 'requests'), bare=True) project = pagure.lib.get_authorized_project( self.session, project_name='test') @@ -58,9 +58,9 @@ class PagureFlaskDeleteRepotests(tests.Modeltests): user='pingou', repo=project, gitfolder=os.path.join(self.path, 'repos'), - docfolder=os.path.join(self.path, 'docs'), - ticketfolder=os.path.join(self.path, 'tickets'), - requestfolder=os.path.join(self.path, 'requests'), + docfolder=os.path.join(self.path, 'repos', 'docs'), + ticketfolder=os.path.join(self.path, 'repos', 'tickets'), + requestfolder=os.path.join(self.path, 'repos', 'requests'), ) pagure.lib.tasks.get_result(task_id).get() diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index 784b38f..a8e0e6a 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -1540,9 +1540,9 @@ class PagureLibtests(tests.Modeltests): def test_new_project(self): """ Test the new_project of pagure.lib. """ gitfolder = os.path.join(self.path, 'repos') - docfolder = os.path.join(self.path, 'docs') - ticketfolder = os.path.join(self.path, 'tickets') - requestfolder = os.path.join(self.path, 'requests') + docfolder = os.path.join(gitfolder, 'docs') + ticketfolder = os.path.join(gitfolder, 'tickets') + requestfolder = os.path.join(gitfolder, 'requests') # Try creating a blacklisted project self.assertRaises( @@ -1561,6 +1561,24 @@ class PagureLibtests(tests.Modeltests): parent_id=None, ) + # Try creating a project that's blacklisted by wildcard match + self.assertRaises( + pagure.exceptions.ProjectBlackListedException, + pagure.lib.new_project, + session=self.session, + user='pingou', + namespace='space', + name='static', + blacklist=['space/*'], + allowed_prefix=[], + gitfolder=gitfolder, + docfolder=docfolder, + ticketfolder=ticketfolder, + requestfolder=requestfolder, + description='description for static', + parent_id=None, + ) + # Try creating a 40 chars project self.assertRaises( pagure.exceptions.PagureException, @@ -1809,9 +1827,9 @@ class PagureLibtests(tests.Modeltests): def test_new_project_user_ns(self): """ Test the new_project of pagure.lib with user_ns on. """ gitfolder = os.path.join(self.path, 'repos') - docfolder = os.path.join(self.path, 'docs') - ticketfolder = os.path.join(self.path, 'tickets') - requestfolder = os.path.join(self.path, 'requests') + docfolder = os.path.join(gitfolder, 'docs') + ticketfolder = os.path.join(gitfolder, 'tickets') + requestfolder = os.path.join(gitfolder, 'requests') # Create a new project with user_ns as True pagure.config.config['GIT_FOLDER'] = gitfolder @@ -2197,9 +2215,9 @@ class PagureLibtests(tests.Modeltests): def test_fork_project_with_branch(self): """ Test the fork_project of pagure.lib. """ gitfolder = os.path.join(self.path, 'repos') - docfolder = os.path.join(self.path, 'docs') - ticketfolder = os.path.join(self.path, 'tickets') - requestfolder = os.path.join(self.path, 'requests') + docfolder = os.path.join(gitfolder, 'docs') + ticketfolder = os.path.join(gitfolder, 'tickets') + requestfolder = os.path.join(gitfolder, 'requests') pagure.config.config['GIT_FOLDER'] = gitfolder projects = pagure.lib.search_projects(self.session) @@ -2281,9 +2299,9 @@ class PagureLibtests(tests.Modeltests): def test_fork_project_namespaced(self): """ Test the fork_project of pagure.lib on a namespaced project. """ gitfolder = os.path.join(self.path, 'repos') - docfolder = os.path.join(self.path, 'docs') - ticketfolder = os.path.join(self.path, 'tickets') - requestfolder = os.path.join(self.path, 'requests') + docfolder = os.path.join(gitfolder, 'docs') + ticketfolder = os.path.join(gitfolder, 'tickets') + requestfolder = os.path.join(gitfolder, 'requests') projects = pagure.lib.search_projects(self.session) self.assertEqual(len(projects), 0) diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index 3202651..e257ef4 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -1546,7 +1546,7 @@ index 9f44358..2a552bb 100644 self.session.commit() # Create repo - self.gitrepo = os.path.join(self.path, 'tickets', + self.gitrepo = os.path.join(self.path, 'repos', 'tickets', 'test_ticket_repo.git') pygit2.init_repository(self.gitrepo, bare=True) @@ -1558,18 +1558,18 @@ index 9f44358..2a552bb 100644 title='Test issue', content='We should work on this', user='pingou', - ticketfolder=os.path.join(self.path, 'tickets') + ticketfolder=os.path.join(self.path, 'repos', 'tickets') ) self.assertEqual(msg.title, 'Test issue') issue = pagure.lib.search_issues(self.session, repo, issueid=1) pagure.lib.git.update_git(issue, repo, os.path.join(self.path, - 'tickets')).get() + 'repos', 'tickets')).get() repo = pygit2.Repository(self.gitrepo) commit = repo.revparse_single('HEAD') # Use patch to validate the repo - patch = pagure.lib.git.commit_to_patch(repo, commit) + commit_patch = pagure.lib.git.commit_to_patch(repo, commit) exp = """Mon Sep 17 00:00:00 2001 From: pagure Subject: Updated issue : Test issue @@ -1615,7 +1615,7 @@ index 0000000..60f7480 """ npatch = [] - for row in patch.split('\n'): + for row in commit_patch.split('\n'): if row.startswith('Date:'): continue elif row.startswith('From '): @@ -1643,9 +1643,9 @@ index 0000000..60f7480 elif row.startswith('+++ b/'): row = '+++ b/456' npatch.append(row) - patch = '\n'.join(npatch) - #print patch - self.assertEqual(patch, exp) + commit_patch = '\n'.join(npatch) + #print commit_patch + self.assertEqual(commit_patch, exp) # Enforce having a different last_updated field # This is required as the test run fine and fast with sqlite but is @@ -1654,20 +1654,25 @@ index 0000000..60f7480 time.sleep(1) # Test again after adding a comment - msg = pagure.lib.add_issue_comment( - session=self.session, - issue=issue, - comment='Hey look a comment!', - user='foo', - ticketfolder=os.path.join(self.path, 'tickets') - ) + # We need to make sure we wait for worker to commit the comment + def _definitely_wait(result): + result.wait() + + with patch('pagure.lib.git._maybe_wait', _definitely_wait): + msg = pagure.lib.add_issue_comment( + session=self.session, + issue=issue, + comment='Hey look a comment!', + user='foo', + ticketfolder=os.path.join(self.path, 'repos', 'tickets') + ) self.session.commit() self.assertEqual(msg, 'Comment added') # Use patch to validate the repo repo = pygit2.Repository(self.gitrepo) commit = repo.revparse_single('HEAD') - patch = pagure.lib.git.commit_to_patch(repo, commit) + commit_patch = pagure.lib.git.commit_to_patch(repo, commit) exp = """Mon Sep 17 00:00:00 2001 From: pagure Subject: Updated issue : Test issue @@ -1716,7 +1721,7 @@ index 458821a..77674a8 """ npatch = [] - for row in patch.split('\n'): + for row in commit_patch.split('\n'): if row.startswith('Date:'): continue elif row.startswith('From '): @@ -1746,9 +1751,9 @@ index 458821a..77674a8 t = row.split(': ')[0] row = '%s: "",' % t npatch.append(row) - patch = '\n'.join(npatch) - # print patch - self.assertEqual(patch, exp) + commit_patch = '\n'.join(npatch) + # print commit_patch + self.assertEqual(commit_patch, exp) def test_clean_git(self): """ Test the clean_git method of pagure.lib.git. """ @@ -1756,7 +1761,8 @@ index 458821a..77674a8 self.test_update_git() - gitpath = os.path.join(self.path, 'tickets', 'test_ticket_repo.git') + gitpath = os.path.join(self.path, 'repos', 'tickets', + 'test_ticket_repo.git') gitrepo = pygit2.init_repository(gitpath, bare=True) # Get the uid of the ticket created @@ -1798,7 +1804,7 @@ index 458821a..77674a8 self.session.commit() # Create repo - self.gitrepo = os.path.join(self.path, 'requests', + self.gitrepo = os.path.join(self.path, 'repos', 'requests', 'test_ticket_repo.git') pygit2.init_repository(self.gitrepo, bare=True) @@ -2727,7 +2733,7 @@ index 0000000..60f7480 """ Test the read_git_lines method of pagure.lib.git. """ self.test_update_git() - gitrepo = os.path.join(self.path, 'tickets', 'test_ticket_repo.git') + gitrepo = os.path.join(self.path, 'repos', 'tickets', 'test_ticket_repo.git') output = pagure.lib.git.read_git_lines( ['log', '-1', "--pretty='%s'"], gitrepo) self.assertEqual(len(output), 1) @@ -2751,7 +2757,7 @@ index 0000000..60f7480 self.test_update_git() - gitrepo = os.path.join(self.path, 'tickets', 'test_ticket_repo.git') + gitrepo = os.path.join(self.path, 'repos', 'tickets', 'test_ticket_repo.git') output = pagure.lib.git.read_git_lines( ['log', '-3', "--pretty='%H'"], gitrepo) self.assertEqual(len(output), 2) @@ -2818,7 +2824,7 @@ index 0000000..60f7480 self.test_update_git() - gitrepo = os.path.join(self.path, 'tickets', 'test_ticket_repo.git') + gitrepo = os.path.join(self.path, 'repos', 'tickets', 'test_ticket_repo.git') output = pagure.lib.git.read_git_lines( ['log', '-3', "--pretty='%H'"], gitrepo) self.assertEqual(len(output), 2)