From 96bea4633a0dea75ce9efa4102ecbc1f60a3317d Mon Sep 17 00:00:00 2001
From: Karsten Hopp <karsten@redhat.com>
Date: Sep 23 2018 10:58:40 +0000
Subject: [PATCH 1/3] fix /pv/pull-request/ready tests


/pv/pull-request/ready doesn't return commit hashes anymore, just a number of commits

Signed-off-by: Karsten Hopp <karsten@redhat.com>

---

diff --git a/tests/test_pagure_flask_internal.py b/tests/test_pagure_flask_internal.py
index ea31a37..47fb632 100644
--- a/tests/test_pagure_flask_internal.py
+++ b/tests/test_pagure_flask_internal.py
@@ -2442,7 +2442,7 @@ class PagureFlaskInternaltests(tests.Modeltests):
         self.assertEqual(js_data['message']['branch_w_pr'], {})
         self.assertListEqual(
             list(js_data['message']['new_branch']), ['feature'])
-        self.assertEqual(len(js_data['message']['new_branch']['feature']['commits']), 2)
+        self.assertEqual(js_data['message']['new_branch']['feature']['commits'], 2)
         self.assertEqual(
             js_data['message']['new_branch']['feature']['target_branch'], 'master')
 
@@ -2570,7 +2570,7 @@ class PagureFlaskInternaltests(tests.Modeltests):
         self.assertEqual(js_data['message']['branch_w_pr'], {})
         self.assertListEqual(
             list(js_data['message']['new_branch']), ['feature'])
-        self.assertEqual(len(js_data['message']['new_branch']['feature']['commits']), 2)
+        self.assertEqual(js_data['message']['new_branch']['feature']['commits'], 2)
         self.assertEqual(
             js_data['message']['new_branch']['feature']['target_branch'], 'master')
 
@@ -2634,7 +2634,7 @@ class PagureFlaskInternaltests(tests.Modeltests):
         self.assertEqual(js_data['message']['branch_w_pr'], {})
         self.assertListEqual(
             list(js_data['message']['new_branch']), ['feature'])
-        self.assertEqual(len(js_data['message']['new_branch']['feature']['commits']), 2)
+        self.assertEqual(js_data['message']['new_branch']['feature']['commits'], 2)
         self.assertEqual(
             js_data['message']['new_branch']['feature']['target_branch'], 'master')
 
@@ -2699,7 +2699,7 @@ class PagureFlaskInternaltests(tests.Modeltests):
         self.assertEqual(js_data['message']['branch_w_pr'], {})
         self.assertListEqual(
             list(js_data['message']['new_branch']), ['feature'])
-        self.assertEqual(len(js_data['message']['new_branch']['feature']['commits']), 1)
+        self.assertEqual(js_data['message']['new_branch']['feature']['commits'], 1)
         self.assertEqual(
             js_data['message']['new_branch']['feature']['target_branch'], 'feature')
 

From b644d3de08c60f248ee34aa52df562a1966c67a3 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Sep 23 2018 10:58:40 +0000
Subject: [PATCH 2/3] Make the internal endpoint return a task id and the client query this task


Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>

---

diff --git a/pagure/internal/__init__.py b/pagure/internal/__init__.py
index 48862d1..ba562c9 100644
--- a/pagure/internal/__init__.py
+++ b/pagure/internal/__init__.py
@@ -296,29 +296,16 @@ def get_pull_request_ready_branch():
             )
             response.status_code = 400
             return response
-    result = pagure.lib.tasks.pull_request_ready_branch.delay(
+    task = pagure.lib.tasks.pull_request_ready_branch.delay(
         namespace=args_namespace,
         name=args_reponame,
         user=args_user,
     )
 
-    try:
-        message = result.get(timeout=100)
-    except celery.exceptions.TimeoutError:
-        result.forget()
-        response = flask.jsonify(
-            {
-                "code": "ERROR",
-                "message": "Timed out while waiting for results",
-            }
-        )
-        response.status_code = 400
-        return response
-
     return flask.jsonify(
         {
             "code": "OK",
-            "message": message,
+            "task": task.id,
         }
     )
 
diff --git a/pagure/templates/repo_master.html b/pagure/templates/repo_master.html
index 0c2b400..654a3c8 100644
--- a/pagure/templates/repo_master.html
+++ b/pagure/templates/repo_master.html
@@ -394,76 +394,90 @@ window.addEventListener("load", function(event) {
 {% if g.authenticated and not g.repo_obj.is_empty %}
 
 {% if g.repo_committer %}
-function process_async(url, _data, callback) {
-  $.post(url, _data, null, dataType='json')
-    .done(function(data) {
-      callback(data);
+var _cnt = 0;
+
+function process_task_results(_data, callback) {
+  var _url = '{{ url_for("internal_ns.task_info", taskid='') }}' + _data.task;
+  $.ajax({
+    url: _url ,
+    type: 'GET',
+    data: {
+      js: 1,
+      count: _cnt,
+    },
+    dataType: 'JSON',
+    success: function(res) {
+      callback(res.results);
       $("#spinnergif").hide();
-    })
+    },
+    error: function(res) {
+      _cnt += 1;
+      if (_cnt < 600) {
+        window.setTimeout(process_task_results, 1000, _data, callback);
+      }
+    }
+  });
 }
 
+
 function generate_branch_list(data) {
-  if (data.code == 'OK') {
-     var _b = $("#dropdown-item-list");
-     var first_item = true;
-     for (branch in data.message.new_branch){
-       if (first_item){
-         _b.prepend("<div class='dropdown-divider'></div>")
-         first_item = false;
-       }
-       var url = "{{ url_for(
-         'ui_ns.new_request_pull',
-         repo=repo.name,
-         username=repo.user.user if repo.is_fork else None,
-         namespace=repo.namespace,
-         branch_to='-',
-         branch_from='-') }}";
-       url = url.slice(0, -4) + data.message.new_branch[branch]['target_branch'] + '..' + branch;
-       html = '<a class="dropdown-item " href="' + url + '">'
-         + '<span class="badge badge-light badge-pill border border-secondary font-size-1">'
-           + ' <i class="fa fa-calendar-o fa-rotate-270 fa-fw"></i> '
-           + '{{ repo.name }}'
-         + '</span> '
-         + '<span class="badge badge-secondary border border-secondary badge-pill font-size-1">'
-           + '<span class="fa fa-random fa-fw"> </span> '
-           + branch
-         + '</span></a> ';
-       _b.prepend(html);
+   var _b = $("#dropdown-item-list");
+   var first_item = true;
+   for (branch in data.new_branch){
+     if (first_item){
+       _b.prepend("<div class='dropdown-divider'></div>")
+       first_item = false;
      }
-     _b.show();
-  }
+     var url = "{{ url_for(
+       'ui_ns.new_request_pull',
+       repo=repo.name,
+       username=repo.user.user if repo.is_fork else None,
+       namespace=repo.namespace,
+       branch_to='-',
+       branch_from='-') }}";
+     url = url.slice(0, -4) + data.new_branch[branch]['target_branch'] + '..' + branch;
+     html = '<a class="dropdown-item " href="' + url + '">'
+       + '<span class="badge badge-light badge-pill border border-secondary font-size-1">'
+         + ' <i class="fa fa-calendar-o fa-rotate-270 fa-fw"></i> '
+         + '{{ repo.name }}'
+       + '</span> '
+       + '<span class="badge badge-secondary border border-secondary badge-pill font-size-1">'
+         + '<span class="fa fa-random fa-fw"> </span> '
+         + branch
+       + '</span></a> ';
+     _b.prepend(html);
+   }
+   _b.show();
 }
 
 function generate_branch_list_fork(data) {
-  if (data.code == 'OK') {
-     var _b = $("#dropdown-item-list");
-     var first_item = true;
-     for (branch in data.message.new_branch){
-       if (first_item){
-         _b.prepend("<div class='dropdown-divider'></div>")
-         first_item = false;
-       }
-       var url = "{{ url_for(
-         'ui_ns.new_request_pull',
-         repo=repo.name,
-         username=g.fas_user.username,
-         namespace=repo.namespace,
-         branch_to='-',
-         branch_from='-') }}";
-       url = url.slice(0, -4) + data.message.new_branch[branch]['target_branch'] + '..' + branch;
-       html = '<a class="dropdown-item " href="' + url + '">'
-         + '<span class="badge badge-light badge-pill border border-secondary font-size-1">'
-           + ' <i class="fa fa-calendar-o fa-rotate-270 fa-fw"></i> '
-           + '{{ g.fas_user.username }}/{{ repo.name }}</span> '
-         + '</span> '
-         + '<span class="badge badge-secondary border border-secondary badge-pill font-size-1">'
-           + '<span class="fa fa-random fa-fw"> </span> '
-           + branch
-         + '</span></a> ';
-       _b.prepend(html);
+   var _b = $("#dropdown-item-list");
+   var first_item = true;
+   for (branch in data.new_branch){
+     if (first_item){
+       _b.prepend("<div class='dropdown-divider'></div>")
+       first_item = false;
      }
-     _b.show();
-  }
+     var url = "{{ url_for(
+       'ui_ns.new_request_pull',
+       repo=repo.name,
+       username=g.fas_user.username,
+       namespace=repo.namespace,
+       branch_to='-',
+       branch_from='-') }}";
+     url = url.slice(0, -4) + data.new_branch[branch]['target_branch'] + '..' + branch;
+     html = '<a class="dropdown-item " href="' + url + '">'
+       + '<span class="badge badge-light badge-pill border border-secondary font-size-1">'
+         + ' <i class="fa fa-calendar-o fa-rotate-270 fa-fw"></i> '
+         + '{{ g.fas_user.username }}/{{ repo.name }}</span> '
+       + '</span> '
+       + '<span class="badge badge-secondary border border-secondary badge-pill font-size-1">'
+         + '<span class="fa fa-random fa-fw"> </span> '
+         + branch
+       + '</span></a> ';
+     _b.prepend(html);
+   }
+   _b.show();
 }
 
 $("#pr-button").one("click",
@@ -497,14 +511,20 @@ $("#pr-button").one("click",
         repouser: "",
         csrf_token: "{{ g.confirmationform.csrf_token.current_token }}",
       };
-  process_async(_pr_url, data, generate_branch_list);
+  $.post(_pr_url, data, null, dataType='json').done(
+    function(data) {
+      process_task_results(data, generate_branch_list);
+  })
   var data = {
         repo: "{{ repo.name }}",
         namespace: "{{ repo.namespace if repo.namespace }}",
         repouser: "{{ g.fas_user.username }}",
         csrf_token: "{{ g.confirmationform.csrf_token.current_token }}",
       };
-  process_async(_pr_url, data, generate_branch_list_fork);
+  $.post(_pr_url, data, null, dataType='json').done(
+    function(data) {
+      process_task_results(data, generate_branch_list);
+  })
   _b.prepend(new_pr);
   }
 );

From 570ce621d5b4820c4495d0765753ae6807f8257f Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Sep 23 2018 10:58:40 +0000
Subject: [PATCH 3/3] Don't use the latest markdown for now


Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>

---

diff --git a/requirements.txt b/requirements.txt
index 392bd0d..48c25c6 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -14,7 +14,7 @@ enum34;python_version<"3.4"
 flask
 flask-wtf
 kitchen
-markdown
+markdown < 3.0
 munch
 Pillow
 psutil

