Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use ghub-continue to retrieve multiple pages #115

Closed
alex-hhh opened this issue Jul 31, 2020 · 1 comment
Closed

cannot use ghub-continue to retrieve multiple pages #115

alex-hhh opened this issue Jul 31, 2020 · 1 comment

Comments

@alex-hhh
Copy link

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))
@tarsius tarsius closed this as completed in ae5b70b Aug 1, 2020
@tarsius
Copy link
Member

tarsius commented Aug 5, 2020

Thanks for the report! I reverted the faulty change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants