From 322961725c3c3cf66865a7990a49c6ea9095a079 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 28 2018 13:58:06 +0000 Subject: Allow linking to the new issue page with a specific template With this commit we can construct link to the new_issue page with a ?template argument taking the name of the template file on disk and show the new_page with that template in. Fixes https://pagure.io/pagure/issue/3759 Signed-off-by: Pierre-Yves Chibon --- diff --git a/doc/usage/tips_tricks.rst b/doc/usage/tips_tricks.rst index 9180fe7..fdfcf35 100644 --- a/doc/usage/tips_tricks.rst +++ b/doc/usage/tips_tricks.rst @@ -18,8 +18,8 @@ Example Text in the square brackets will be used as an alt description. -Pre-fill issue template using the URL -------------------------------------- +Pre-fill issue using the URL +---------------------------- When creating issues for a project pagure supports pre-filling the title and description input text using URL parameters. @@ -32,6 +32,21 @@ The above URL will autofill the text boxes for Title and Description field with Title set to and Description set to . +Pre-fill issue template using the URL +------------------------------------- + +When creating issues for a project pagure supports pre-filling the title +and description input text using URL parameters. + +Example: +~~~~~~~~ +https://pagure.io/pagure/new_issue/?template= + +The above URL will autofill the ticket with the specified template. The +TemplateName should be the name of the template file on disk (in the +``templates`` directory of the ticket git repository). + + Filter for issues *not* having a certain tag -------------------------------------------- diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index 8c2c6c8..e1bef85 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -868,6 +868,7 @@ def view_milestone(repo, username=None, namespace=None, milestone=None): def new_issue(repo, username=None, namespace=None): """ Create a new issue """ + template = flask.request.args.get("template") or "default" repo = flask.g.repo milestones = [] @@ -997,13 +998,16 @@ def new_issue(repo, username=None, namespace=None): ) if files: types = [f.name.rsplit(".md", 1)[0] for f in files] - # Get the default template - default_file = __get_file_in_tree( - ticketrepo, - commit.tree, - ["templates", "default.md"], - bail_on_tree=True, - ) + + default_file = None + if types and template in types: + # Get the template + default_file = __get_file_in_tree( + ticketrepo, + commit.tree, + ["templates", "%s.md" % template], + bail_on_tree=True, + ) if default_file: default, _ = pagure.doc_utils.convert_readme( default_file.data, "md" diff --git a/tests/test_pagure_flask_ui_issues_templates.py b/tests/test_pagure_flask_ui_issues_templates.py index ae57ad4..3f1ea4e 100644 --- a/tests/test_pagure_flask_ui_issues_templates.py +++ b/tests/test_pagure_flask_ui_issues_templates.py @@ -174,6 +174,36 @@ class PagureFlaskIssuesTemplatetests(tests.Modeltests): self.assertIn( 'default', output_text) + self.assertIn( + 'placeholder="Enter your comment here" tabindex=1 required>' + 'Report your issue', output_text) + + def test_new_issue_w_specific_template(self): + """ Test the new_issue endpoint when the project has templates. """ + + user = tests.FakeUser() + with tests.user_set(self.app.application, user): + output = self.app.get('/test2/new_issue?template=2018-bid') + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn( + '

New Issue

\n', + output_text) + self.assertIn( + 'Issue Templates', + output_text) + self.assertIn( + 'RFE', + output_text) + self.assertIn( + '2018-bid', + output_text) + self.assertIn( + 'default', + output_text) + self.assertIn( + 'placeholder="Enter your comment here" tabindex=1 required>' + 'Bid for 2018\n############', output_text) def test_get_ticket_template_no_csrf(self): """ Test the get_ticket_template endpoint when the project has no