From c1f3f7e6810571eb62912bd4dd0666d0d121bc86 Mon Sep 17 00:00:00 2001 From: Abdelhak Bougouffa Date: Fri, 6 Jan 2023 21:52:04 +0100 Subject: [PATCH] utils: A helper to get the latest release from github --- dap-utils.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dap-utils.el b/dap-utils.el index fe5c23c1..08b907fc 100644 --- a/dap-utils.el +++ b/dap-utils.el @@ -102,14 +102,25 @@ PATH is the download destination dir." (f-join dap-utils-extension-path "openvsx" (concat publisher "." name))))) (dap-utils--get-extension url dest))) -(defun dap-utils-get-github-extension (owner repo version &optional path) +(defun dap-utils-get-github-extension (owner repo &optional version path) "Get extension from github named OWNER/REPO with VERSION. PATH is the download destination path." - (let* ((url (format dap-utils-github-extension-url owner repo version)) + (let* ((version (or version (dap-utils-get-github-extension-latest-version owner repo))) + (url (format dap-utils-github-extension-url owner repo version)) (dest (or path (f-join dap-utils-extension-path "github" (concat owner "." repo))))) (dap-utils--get-extension url dest))) +(defun dap-utils-get-github-extension-latest-version (owner repo) + (let ((latest + (with-temp-buffer + (url-insert-file-contents + (format + "https://api.github.com/repos/%s/%s/releases/latest" + owner repo)) + (json-parse-buffer :object-type 'plist)))) + (car (last (split-string (plist-get latest :html_url) "/"))))) + (defun dap-utils-vscode-get-installed-extension-version (path) "Check the version of the vscode extension installed in PATH. Returns nil if the extension is not installed."