From 0915d04a8786654e597937187e6052871ceae613 Mon Sep 17 00:00:00 2001 From: Slavek Kabrda Date: Nov 02 2018 10:09:34 +0000 Subject: Get repotypes dynamically, consider config values --- diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index 0b341de..ac71ff6 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -73,8 +73,8 @@ class BaseRunner(object): session (Session): Database session username (string): The user performing a push project (model.Project): The project this call is made for - repotype (string): Value of lib.REPOTYPES indicating for which - repo the current call is + repotype (string): Value of lib.query.get_repotypes() indicating + for which repo the current call is repodir (string): Directory where a clone of the specified repo is located. Do note that this might or might not be a writable clone. @@ -165,7 +165,7 @@ class BaseHook(object): os.path.dirname(os.path.realpath(__file__)), "files" ) - for repotype in pagure.lib.query.REPOTYPES: + for repotype in pagure.lib.query.get_repotypes(): repopath = project.repopath(repotype) if repopath is None: continue @@ -281,8 +281,8 @@ def run_project_hooks( session: Database session username (string): The user performing a push project (model.Project): The project this call is made for - repotype (string): Value of lib.REPOTYPES indicating for which - repo the currnet call is + repotype (string): Value of lib.query.get_repotypes() indicating + for which repo the currnet call is repodir (string): Directory where a clone of the specified repo is located. Do note that this might or might not be a writable clone. diff --git a/pagure/lib/git.py b/pagure/lib/git.py index ce5d3f9..6725076 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -883,7 +883,7 @@ class TemporaryClone(object): action (string): Type of action performing, used in the temporary directory name """ - if repotype not in pagure.lib.query.REPOTYPES: + if repotype not in pagure.lib.query.get_repotypes(): raise NotImplementedError("Repotype %s not known" % repotype) self._project = project @@ -2199,7 +2199,7 @@ def delete_project_repos(project): Args: project (Project): Project to delete repos for """ - for repotype in pagure.lib.query.REPOTYPES: + for repotype in pagure.lib.query.get_repotypes(): if project.is_on_repospanner: _, regioninfo = project.repospanner_repo_info(repotype) @@ -2264,7 +2264,7 @@ def set_up_project_hooks(project, region, hook=None): # No hooks to set up for this region return - for repotype in pagure.lib.query.REPOTYPES: + for repotype in pagure.lib.query.get_repotypes(): data = { "Reponame": project._repospanner_repo_name(repotype, region), "UpdateRequest": { @@ -2383,7 +2383,7 @@ def create_project_repos(project, region, templ, ignore_existing): created_dirs = [] try: - for repotype in pagure.lib.query.REPOTYPES: + for repotype in pagure.lib.query.get_repotypes(): created = _create_project_repo( project, region, templ, ignore_existing, repotype ) diff --git a/pagure/lib/git_auth.py b/pagure/lib/git_auth.py index 008e96d..dd7e182 100644 --- a/pagure/lib/git_auth.py +++ b/pagure/lib/git_auth.py @@ -158,8 +158,8 @@ class GitAuthHelper(with_metaclass(abc.ABCMeta, object)): - revto (string): The commit hash the update is happening to. - pull_request (model.PullRequest or None): The PR that is trying to be merged. - - repotype (string): The pagure.lib.query.REPOTYPES value for the - repo being pushed to. + - repotype (string): The pagure.lib.query.get_repotypes() value + for the repo being pushed to. - repodir (string): A directory containing the current repository, including the new objects to be approved. Note that this might or might not be directly writable, and any diff --git a/pagure/lib/query.py b/pagure/lib/query.py index b4ef6aa..9ae5047 100644 --- a/pagure/lib/query.py +++ b/pagure/lib/query.py @@ -68,13 +68,21 @@ from pagure.lib import tasks_services REDIS = None PAGURE_CI = None -REPOTYPES = ("main", "docs", "tickets", "requests") _log = logging.getLogger(__name__) # The target for hooks migrated to the Runner system, to be able to detect # whether a hook was migrated without having to open and read the file HOOK_DNE_TARGET = "/does/not/exist" +def get_repotypes(): + rt = ["main", "requests"] + if pagure_config["ENABLE_TICKETS"]: + rt.append("tickets") + if pagure_config["ENABLE_DOCS"]: + rt.append("docs") + return tuple(rt) + + class Unspecified(object): """ Custom None object used to indicate that the caller has not made a choice for a particular argument. diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index 39486e9..c8630c0 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -618,7 +618,7 @@ def move_to_repospanner(self, session, name, namespace, user, region): # Make sure that no non-runner hooks are enabled for this project compatible_targets = [pagure.lib.query.HOOK_DNE_TARGET] incompatible_hooks = [] - for repotype in pagure.lib.query.REPOTYPES: + for repotype in pagure.lib.query.get_repotypes(): path = project.repopath(repotype) if path is None: continue @@ -645,7 +645,7 @@ def move_to_repospanner(self, session, name, namespace, user, region): # Create the repositories pagure.lib.git.create_project_repos(project, region, None, False) - for repotype in pagure.lib.query.REPOTYPES: + for repotype in pagure.lib.query.get_repotypes(): repopath = project.repopath(repotype) if repopath is None: continue @@ -671,7 +671,7 @@ def move_to_repospanner(self, session, name, namespace, user, region): ) _log.debug("Out: %s" % out) - for repotype in pagure.lib.query.REPOTYPES: + for repotype in pagure.lib.query.get_repotypes(): repopath = project.repopath(repotype) if repopath is None: continue diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index 37ba1b0..29bf980 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -391,6 +391,36 @@ class PagureLibtests(tests.Modeltests): maxDiff = None + def test_get_repotypes(self): + """ Test the get_repotypes function of pagure.lib.query. """ + with patch.dict(pagure.config.config, + {"ENABLE_TICKETS": False, "ENABLE_DOCS": False}): + self.assertEqual( + set(("main", "requests")), + set(pagure.lib.query.get_repotypes()) + ) + + with patch.dict(pagure.config.config, + {"ENABLE_TICKETS": True, "ENABLE_DOCS": False}): + self.assertEqual( + set(("main", "requests", "tickets")), + set(pagure.lib.query.get_repotypes()) + ) + + with patch.dict(pagure.config.config, + {"ENABLE_TICKETS": False, "ENABLE_DOCS": True}): + self.assertEqual( + set(("main", "requests", "docs")), + set(pagure.lib.query.get_repotypes()) + ) + + with patch.dict(pagure.config.config, + {"ENABLE_TICKETS": True, "ENABLE_DOCS": True}): + self.assertEqual( + set(("main", "requests", "tickets", "docs")), + set(pagure.lib.query.get_repotypes()) + ) + def test_get_next_id(self): """ Test the get_next_id function of pagure.lib.query. """ tests.create_projects(self.session)