#3771 Allow linking to the new issue page with a specific template
Merged 6 years ago by pingou. Opened 6 years ago by pingou.

file modified
+17 -2
@@ -18,8 +18,8 @@ 

  

  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 @@ 

  with Title set to <Issue> and Description set to <Issue Content>.

  

  

+ 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=<TemplateName>

+ 

+ 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

  --------------------------------------------

  

file modified
+11 -7
@@ -868,6 +868,7 @@ 

  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 @@ 

              )

              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"

@@ -174,6 +174,36 @@ 

              self.assertIn(

                  '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="default">default</a>',

                  output_text)

+             self.assertIn(

+                 'placeholder="Enter your comment here" tabindex=1 required>'

+                 'Report your issue</textarea>', 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(

+                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n',

+                 output_text)

+             self.assertIn(

+                 'Issue Templates',

+                 output_text)

+             self.assertIn(

+                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="RFE">RFE</a>',

+                 output_text)

+             self.assertIn(

+                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="2018-bid">2018-bid</a>',

+                 output_text)

+             self.assertIn(

+                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="default">default</a>',

+                 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

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 pingou@pingoured.fr

rebased onto 1237a158f9f55431b7867e7cbf0c076d71570035

6 years ago

rebased onto bb5ea83e18694761b910744d0fe499970e4e6817

6 years ago

I've added a section in the doc in the Tips & Tricks page. Would you like to review it?

rebased onto 3229617

6 years ago

Pull-Request has been merged by pingou

6 years ago