From aa8dfb182cfdcc5435a102ad01a8b44e55b9f3e9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 04 2020 08:44:54 +0000 Subject: [PATCH 1/2] Allow to specify a default branch for all projects hosted on an instance Basically, with this feature we can define the default git branch for all the new projects created in that pagure instance. This default branch can always be overriden by the user upon creation, but if the user does not specify a default branch, it will be using this one. Fixes https://pagure.io/pagure/issue/5054 Signed-off-by: Pierre-Yves Chibon --- diff --git a/doc/configuration.rst b/doc/configuration.rst index 2ea7a66..9538f71 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1912,6 +1912,17 @@ When set to ``False``, this essentially makes the API ignore whether the Default to: ``True`` +GIT_DEFAULT_BRANCH +~~~~~~~~~~~~~~~~~~ + +This configuration key allows to specify the default branch configured upon +project creation. The default branch can be specified by the user upon project +creation but if the user does not specify any branch, this branch name will be +used. + +Defaults to: ``None`` (which results in the default branch being ``master``). + + RepoSpanner Options ------------------- diff --git a/pagure/lib/query.py b/pagure/lib/query.py index 9b8b3ec..513a4aa 100644 --- a/pagure/lib/query.py +++ b/pagure/lib/query.py @@ -1738,7 +1738,7 @@ def new_project( name, add_readme, ignore_existing_repo, - default_branch, + default_branch or pagure_config.get("GIT_DEFAULT_BRANCH"), ) diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index 4d8ecab..8c10a35 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -2517,6 +2517,89 @@ class PagureFlaskAppNewProjecttests(tests.Modeltests): repo = pygit2.Repository(projects[0].repopath("main")) self.assertEqual(repo.listall_branches(), ["main"]) + @patch.dict("pagure.config.config", {"GIT_DEFAULT_BRANCH": "main"}) + def test_new_project_with_default_branch_instance_wide(self): + """ Test the new_project endpoint when new project contains a plus sign. + """ + # Before + projects = pagure.lib.query.search_projects(self.session) + self.assertEqual(len(projects), 0) + + user = tests.FakeUser(username="foo") + with tests.user_set(self.app.application, user): + csrf_token = self.get_csrf() + + data = { + "description": "Project #1.", + "name": "project_main", + "csrf_token": csrf_token, + "create_readme": True, + } + output = self.app.post("/new/", data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn( + "Overview - project_main - Pagure", output_text + ) + self.assertIn( + 'project_main', + output_text, + ) + self.assertIn( + 'main', + output_text, + ) + + # After + projects = pagure.lib.query.search_projects(self.session) + self.assertEqual(len(projects), 1) + + repo = pygit2.Repository(projects[0].repopath("main")) + self.assertEqual(repo.listall_branches(), ["main"]) + + @patch.dict("pagure.config.config", {"GIT_DEFAULT_BRANCH": "main"}) + def test_new_project_with_default_branch_instance_wide_overriden(self): + """ Test the new_project endpoint when new project contains a plus sign. + """ + # Before + projects = pagure.lib.query.search_projects(self.session) + self.assertEqual(len(projects), 0) + + user = tests.FakeUser(username="foo") + with tests.user_set(self.app.application, user): + csrf_token = self.get_csrf() + + data = { + "description": "Project #1.", + "name": "project_main", + "csrf_token": csrf_token, + "default_branch": "rawhide", + "create_readme": True, + } + output = self.app.post("/new/", data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn( + "Overview - project_main - Pagure", output_text + ) + self.assertIn( + 'project_main', + output_text, + ) + self.assertIn( + 'rawhide', + output_text, + ) + + # After + projects = pagure.lib.query.search_projects(self.session) + self.assertEqual(len(projects), 1) + + repo = pygit2.Repository(projects[0].repopath("main")) + self.assertEqual(repo.listall_branches(), ["rawhide"]) + def test_new_project_when_turned_off(self): """ Test the new_project endpoint when new project creation is not allowed in the pagure instance. """ From 16570d574653b336c5e3f99b43f33942fd72de2c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 04 2020 08:44:54 +0000 Subject: [PATCH 2/2] Move the PAGURE_PLUGINS_CONFIG configuration key to a better place Signed-off-by: Pierre-Yves Chibon --- diff --git a/doc/configuration.rst b/doc/configuration.rst index 9538f71..133a8be 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1909,8 +1909,16 @@ existing git tags via the API. When set to ``False``, this essentially makes the API ignore whether the ``force`` argument is set or not. +Defaults to: ``True`` + + +PAGURE_PLUGINS_CONFIG +~~~~~~~~~~~~~~~~~~~~~~ + +This option can be used to specify the configuration file used for loading +plugins. It is not set by default, instead if must be declared explicitly. +Also see the documentation on plugins at :ref:`plugins`. -Default to: ``True`` GIT_DEFAULT_BRANCH ~~~~~~~~~~~~~~~~~~ @@ -2069,6 +2077,7 @@ SSH_COMMAND_NON_REPOSPANNER The command to run if a repository is not on repospanner when aclchecker is in use. + MQTT Options ------------ @@ -2189,13 +2198,6 @@ notifications on commits made on all projects in a pagure instance. Defaults to: ``False``. -PAGURE_PLUGINS_CONFIG -~~~~~~~~~~~~~~~~~~~~~~ - -This option can be used to specify the configuration file used for loading -plugins. It is not set by default, instead if must be declared explicitly. -Also see the documentation on plugins at :ref:`plugins`. - Deprecated configuration keys -----------------------------