cannot use `ghub-continue` to retrieve multiple pages
alex-hhh opened this issue · comments
I have some ELisp code which uses the ghub
package to find the pull request for a branch in GitHub. Since there are many pull requests open, my code uses ghub-continue
inside the callback for ghub-request
to retrieve additional page (using unpaginate is inefficient since there are many pages and the pull request I look for is usually on the first few pages).
This strategy used to work, but when I updated to the recent version of this package from MELPA it broke, as in ghub-continue
keeps retrieving the same page and never finishes retrieving pages as there is always a next one.
The fix that I found was to update ghub--handle-respones
to prepare the next URL even if unpaginate
is not set:
diff --git a/ghub.el~ b/ghub.el
index 2658546..c0a7673 100644
--- a/ghub.el~
+++ b/ghub.el
@@ -525,6 +525,9 @@ and https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341.")
req headers payload)))))
(when (numberp unpaginate)
(cl-decf unpaginate))
+ ;; AH (30/Jul/2020) update the next link even if we don't unpaginate
+ (when next
+ (setf (ghub--req-url req) (url-generic-parse-url next)))
(or (and next
unpaginate
(or (eq unpaginate t)
For reference, this is the code that I am using (it is part of a larger package):
(defun hh-assoc* (alist &rest keys)
(let ((items alist))
(dolist (k keys) (setq items (assoc k items)))
(cdr items)))
(defun hh-github-find-pull-request-for-branch (preqs branch)
(cl-find-if (lambda (preq) (equal branch (hh-assoc* preq 'head 'ref))) preqs))
(defun hh-github-find-pull-request (owner repo branch)
(let ((result nil)
(wait-counter 1000)
(page-number 1)
(have-result? nil))
(ghub-request
"GET" (format "/repos/%s/%s/pulls" owner repo) nil
:query '((state . "open"))
:auth 'hey-hay
:callback (lambda (preqs _headers _status req)
(let ((p (hh-github-find-pull-request-for-branch preqs branch)))
(if p
(progn
(setq result p)
(setq have-result? t))
(setq page-number (1+ page-number))
(message "Fetching next page %s..." page-number)
(unless (ghub-continue req)
(setq have-result? t))))))
(while (and (not have-result?) (> wait-counter 0))
(setq wait-counter (1- wait-counter))
(sit-for 0.5))
result))
Thanks for the report! I reverted the faulty change.