Skip to content

Instantly share code, notes, and snippets.

@jthomasmock
Created October 31, 2024 00:50
Show Gist options
  • Save jthomasmock/5c76eb6f29c7110e6604c5d49f19b07f to your computer and use it in GitHub Desktop.
Save jthomasmock/5c76eb6f29c7110e6604c5d49f19b07f to your computer and use it in GitHub Desktop.
Query OpenVSX API for versions of extensions compatible with specific minimum version of Code OSS
library(httr2)
library(semver)
library(glue)
get_compatible_ext <- function(namespace, name, code_version){
url <- glue::glue("https://open-vsx.org/api/{namespace}/{name}/latest")
raw_ext_json <- httr2::request(url) %>%
req_headers(accept = "application/json") %>% req_perform() %>% resp_body_json()
all_versions_string <- as.character(raw_ext_json$allVersions)
all_versions_string <- all_versions_string[!grepl("latest$", all_versions_string)]
# loop across all of the possible versions of extension and check if they are compatible
for (url in all_versions_string) {
tryCatch({
request <- request(url) %>% req_headers(accept = "application/json")
response <- req_perform(request)
json_data <- resp_body_json(response)
# Extract minimum vscode/code-server version
min_engine <- gsub("^\\^", "", json_data$engines$vscode)
# compare semantic versions of code/vs code
if (semver::parse_version(code_version) >= semver::parse_version(min_engine)) {
replace_api_with_extension <- function(url_in) {
gsub("https://open-vsx.org/api/", "https://open-vsx.org/extension/", url_in)
}
out_url <- replace_api_with_extension(url)
print(paste("Extension version found:", out_url, "Code Server version:", code_version, "is greater than" , min_engine))
break # Stop looping once the minimum version is reached
} else {
print(paste("Version", min_engine, "from", url, "is below the minimum required of", code_version))
}
}, error = function(e) {
print(paste("Error processing URL:", url, ":", e$message))
# Decide whether to continue or stop on error
})
}
}
get_compatible_ext(namespace = "eamodio", name = "gitlens", code_version = "1.50.0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment