@@ -95,13 +95,6 @@ only serves as documentation.")
95
95
(defvar ghub-insecure-hosts nil
96
96
" List of hosts that use http instead of https." )
97
97
98
- (defvar ghub-json-use-jansson nil
99
- " Whether to use the Jansson library, if available.
100
- This is experimental. Only let-bind this but do not enable it
101
- globally because doing that is likely to break other packages
102
- that use `ghub' . As a user also do not enable this yet.
103
- See https://github.com/magit/ghub/pull/149." )
104
-
105
98
(defvar ghub-debug nil
106
99
" Record additional debug information." )
107
100
@@ -601,35 +594,25 @@ Signal an error if the id cannot be determined."
601
594
url-http-response-status))
602
595
603
596
(defun ghub--read-json-payload (_status )
604
- (let ((raw (ghub--decode-payload)))
605
- (and raw
606
- (condition-case nil
607
- (if (and ghub-json-use-jansson
608
- (fboundp 'json-parse-string ))
609
- (json-parse-string
610
- raw
611
- :object-type 'alist
612
- :array-type 'list
613
- :false-object nil
614
- :null-object nil )
615
- (require 'json )
616
- (let ((json-object-type 'alist )
617
- (json-array-type 'list )
618
- (json-false nil )
619
- (json-null nil ))
620
- (json-read-from-string raw)))
621
- ((json-parse-error json-readtable-error)
622
- (pop-to-buffer (current-buffer ))
623
- (setq-local ghub-debug t )
624
- `((message
625
- . ,(if (looking-at " <!DOCTYPE html>" )
626
- (if (re-search-forward
627
- " <p>\\ (?:<strong>\\ )?\\ ([^<]+\\ )" nil t )
628
- (match-string 1 )
629
- " error description missing" )
630
- (string-trim (buffer-substring (point ) (point-max )))))
631
- (documentation_url
632
- . " https://github.com/magit/ghub/wiki/Github-Errors" )))))))
597
+ (and-let* ((payload (ghub--decode-payload)))
598
+ (ghub--assert-json-available)
599
+ (condition-case nil
600
+ (json-parse-string payload
601
+ :object-type 'alist
602
+ :array-type 'list
603
+ :null-object nil
604
+ :false-object nil )
605
+ (json-parse-error
606
+ (pop-to-buffer (current-buffer ))
607
+ (setq-local ghub-debug t )
608
+ `((message . ,(if (looking-at " <!DOCTYPE html>" )
609
+ (if (re-search-forward
610
+ " <p>\\ (?:<strong>\\ )?\\ ([^<]+\\ )" nil t )
611
+ (match-string 1 )
612
+ " error description missing" )
613
+ (string-trim (buffer-substring (point ) (point-max )))))
614
+ (documentation_url
615
+ . " https://github.com/magit/ghub/wiki/Github-Errors" ))))))
633
616
634
617
(defun ghub--decode-payload (&optional _status )
635
618
(and (not (eobp ))
@@ -638,24 +621,15 @@ Signal an error if the id cannot be determined."
638
621
'utf-8 )))
639
622
640
623
(defun ghub--encode-payload (payload )
641
- (and payload
642
- (progn
643
- (unless (stringp payload)
644
- (setq payload
645
- (if (and ghub-json-use-jansson
646
- (fboundp 'json-serialize ))
647
- (json-serialize payload
648
- ; ; :object-type and :array-type
649
- ; ; are not supported here.
650
- :false-object nil
651
- :null-object :null )
652
- (require 'json )
653
- (let ((json-object-type ghub-json-object-type)
654
- (json-array-type ghub-json-array-type)
655
- (json-false nil )
656
- (json-null :null ))
657
- (json-encode payload)))))
658
- (encode-coding-string payload 'utf-8 ))))
624
+ (cl-typecase payload
625
+ (null nil )
626
+ (string (encode-coding-string payload 'utf-8 ))
627
+ (t (ghub--assert-json-available)
628
+ (encode-coding-string
629
+ (json-serialize payload
630
+ :null-object :null
631
+ :false-object nil )
632
+ 'utf-8 ))))
659
633
660
634
(defun ghub--url-encode-params (params )
661
635
(mapconcat (lambda (param )
@@ -667,6 +641,11 @@ Signal an error if the id cannot be determined."
667
641
(t (url-hexify-string val))))))
668
642
params " &" ))
669
643
644
+ (defun ghub--assert-json-available ()
645
+ (unless (and (fboundp 'json-available-p )
646
+ (json-available-p))
647
+ (error " Ghub requires Emacs 29 --with-json or Emacs >= 30 " )))
648
+
670
649
; ;; Authentication
671
650
; ;;; API
672
651
0 commit comments