From f7f2b4d690427a658f7ffaa7266d4680befb71c0 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 17 2020 09:20:31 +0000 Subject: Add support for customizing the new issue page This commit adds the feature allowing to customize the new issue page using a similar feature to the one used in the new PR page. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/new_issue.html b/pagure/templates/new_issue.html index f880410..1034d79 100644 --- a/pagure/templates/new_issue.html +++ b/pagure/templates/new_issue.html @@ -49,6 +49,13 @@ {% endif %} {% endif %}
+ + {% if contributing %} +
+ {{ contributing | markdown | noJS | safe}} +
+ {% endif %} + {% if type == 'edit' %} {{ form.status(class_="hidden") }}
diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index a10cc67..4682f34 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -1030,6 +1030,7 @@ def new_issue(repo, username=None, namespace=None): types = None default = None + contributing = None ticketrepopath = repo.repopath("tickets") if os.path.exists(ticketrepopath): ticketrepo = pygit2.Repository(ticketrepopath) @@ -1040,7 +1041,11 @@ def new_issue(repo, username=None, namespace=None): ticketrepo, commit.tree, ["templates"], bail_on_tree=True ) if files: - types = [f.name.rsplit(".md", 1)[0] for f in files] + types = [ + f.name.rsplit(".md", 1)[0] + for f in files + if f.name not in ["contributing.md"] + ] default_file = None if types and template in types: @@ -1056,6 +1061,17 @@ def new_issue(repo, username=None, namespace=None): default_file.data, "md" ) + contributing = __get_file_in_tree( + ticketrepo, + commit.tree, + ["templates", "contributing.md"], + bail_on_tree=True, + ) + if contributing: + contributing, _ = pagure.doc_utils.convert_readme( + contributing.data, "md" + ) + tag_list = pagure.lib.query.get_tags_of_project(flask.g.session, repo) if flask.request.method == "GET": form.private.data = repo.settings.get( @@ -1082,6 +1098,7 @@ def new_issue(repo, username=None, namespace=None): default=default, tag_list=tag_list, open_access=open_access, + contributing=contributing, ) diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py index 5ffb42e..6aba6c6 100644 --- a/tests/test_pagure_flask_ui_issues.py +++ b/tests/test_pagure_flask_ui_issues.py @@ -199,6 +199,35 @@ class PagureFlaskIssuestests(tests.Modeltests): ) self.assertEqual(output.status_code, 404) + @patch("pagure.lib.git.update_git", MagicMock(return_value=True)) + @patch("pagure.lib.notify.send_email", MagicMock(return_value=True)) + def test_new_issue_customized(self): + """ Test the new_issue endpoint. """ + tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, "repos"), bare=True) + tests.create_projects_git( + os.path.join(self.path, "repos", "tickets"), bare=True + ) + tests.add_content_to_git( + os.path.join(self.path, "repos", "tickets", "test.git"), + branch="master", + folders="templates", + filename="contributing.md", + content="This is a text pulled from the contributing template", + message="Add a contributing.md template", + ) + + user = tests.FakeUser() + with tests.user_set(self.app.application, user): + output = self.app.get("/test/new_issue") + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn("New Issue", output_text) + self.assertIn( + "This is a text pulled from the contributing template", + output_text, + ) + @patch("pagure.lib.git.update_git") @patch("pagure.lib.notify.send_email") def test_new_issue_w_file(self, p_send_email, p_ugt):