#1149 Avoid quering issue tracker when it's disabled on the instance
Merged 7 years ago by pingou. Opened 7 years ago by vivekanand1101.
vivekanand1101/pagure pr  into  master

@@ -1199,25 +1199,45 @@ 

       }

       $("#comment").atwho(userConfig);

     });

-    $.when($.get("{{ url_for('api_ns.api_view_issues', repo=repo.name, username=username, status='all') }}"),

-           $.get("{{ url_for('api_ns.api_pull_request_views', repo=repo.name, username=username, status='all') }}")

-    ).done(function(issuesResp, prResp) {

-      // 0 is the api response

-      var issuesAndPrs = issuesResp[0]['issues'].concat(prResp[0]['requests']);

-      var data = $.map(issuesAndPrs, function(ticket, idx) {

-        return {

-          name: ticket.id.toString(),

-          title: $('<div>').text(ticket.title).html()

+ 

+    {% if config.get('ENABLE_TICKETS', True) %}

+      $.when($.get("{{ url_for('api_ns.api_view_issues', repo=repo.name, username=username, status='all') }}"),

+             $.get("{{ url_for('api_ns.api_pull_request_views', repo=repo.name, username=username, status='all') }}")

+      ).done(function(issuesResp, prResp) {

+        // 0 is the api response

+        var issuesAndPrs = issuesResp[0]['issues'].concat(prResp[0]['requests']);

+        var data = $.map(issuesAndPrs, function(ticket, idx) {

+          return {

+            name: ticket.id.toString(),

+            title: $('<div>').text(ticket.title).html()

+          }

+        });

+        var issueAndPrConfig = {

+          at: '#',

+          data: data,

+          insertTpl: '#${name}',

+          displayTpl: "<li>#${name}<small> ${title}</small></li>",

         }

-      });

-      var issueAndPrConfig = {

-        at: '#',

-        data: data,

-        insertTpl: '#${name}',

-        displayTpl: "<li>#${name}<small> ${title}</small></li>",

-      }

-      $("#comment").atwho(issueAndPrConfig);

-     });

+        $("#comment").atwho(issueAndPrConfig);

+       });

+    {% else %}

+      $.get("{{ url_for('api_ns.api_pull_request_views', repo=repo.name, username=username, status='all') }}")

+          .done(function(prResp) {

+              var data = $.map(prResp['requests'], function(pr, idx) {

+                  return {

+                      name: pr.id.toString(),

+                      title: $('<div>').text(pr.title).html()

+                  }

+              });

+              var conf = {

+                  at: '#',

+                  data: data,

+                  insertTpl: '#${name}',

+                  displayTpl: "<li>#${name}<small> ${title} </small></li>",

+              }

+              $("#comment").atwho(conf);

+          });

+     {% endif %}

  } );

  $(window).on('hashchange', updateHighlight);

  var selected = [];

This is not complete yet. The thing is it is able to query and show the options but when you press "Update", the link doesn't get created. It happens only when the issue tracker is turned off on the instance (the change is for that case only)

Forgot to mention, i need a little help. @atelic

You should have pinged @atelic in a new comment, no notifications are sent upon edit :)

@vivekanand1101 It looks like the links don't get created if ENABLE_TICKETS is True even if I remove the atwho code. This might be expected behavior: https://pagure.io/pagure/blob/master/f/pagure/pfmarkdown.py#_175

@pingou Thoughts?

As for the actual code in the PR, it looks good to me. It works and prevents the routing.BuildError :thumbsup:

This might be expected behavior: https://pagure.io/pagure/blob/master/f/pagure/pfmarkdown.py#_175

You're right, this if is a little to stringent, we should make it more relax since we now support linking to PR via #<id>

Let's rebase and merge :)

FTR I'm not the most happy w/ the code as it feels a little redundant, but for not that'll do :)

rebased

7 years ago

Pull-Request has been merged by pingou

7 years ago
Metadata