Description
Scope
Extension development
Explanation
To do that, extension would need a configuration inside the conf.yml
that points to a url that contains version informations.
For now, that could be a link to the extension from builtbybit.com
, sourcexchange.net
or just to the github
release section.
With that link, the current available version can be parsed and compared against the current installed version.
If the version does not match, then a small icon could be displayed in the extension overview at the extension, which informs the admin that a new version is available for this extension.
Edit: website
parameter inside the conf.yml
should already have that information I guess.
With a get request to that website and a simple query you can already get the current version pretty fast:
builtbybit.com:
document.getElementsByClassName("resourceVersion")[0].innerHTML
;
sourcexchange.nat:
document.getElementById("information-heading").nextElementSibling.innerHTML.match(/v([^\s]+)/)[1];
github.com:
Add /releases/latest
to the url and change the first part from https://github.com/
to https://api.github.com/repos/
.
Example:
https://github.com/BlueprintFramework/framework/
will be https://api.github.com/repos/BlueprintFramework/framework/releases/latest
.
This API call will have the latest version inside the tag_name
property.
Another Edit:
I am not a php guy but something like that should work. Maybe this could be binded to a button "Check for extension updates" in the overview to not throw a bunch of requests every time you access the extension overview.
function getVersionFromUrl($extension_url) {
$context = stream_context_create(["http" => ["header" => "User-Agent: x"]]);
$data = @file_get_contents($extension_url, false, $context);
if (strpos($extension_url, "github.com") !== false) {
$api_url = "https://api.github.com/repos" . parse_url($extension_url, PHP_URL_PATH);
$api_url = rtrim($api_url, "/") . "/releases/latest";
$data = @file_get_contents($api_url, false, $context);
if ($data) {
$version = json_decode($data)->tag_name;
return $version ? $version : null;
}
} elseif (strpos($extension_url, "sourcexchange.net") !== false) {
if ($data && preg_match('/Release v([^\s]+)/', $data, $matches)) {
return trim($matches[1]);
}
} elseif (strpos($extension_url, "builtbybit.com") !== false) {
if ($data && preg_match('/<span class="resourceVersion">v([^<]+)<\/span>/', $data, $matches)) {
return trim($matches[1]);
}
}
return null;
}
This will return the latest version if a valid url is given. Will return null
if the website isn't valid or can't be reached.
Is there an existing issue for this?
- I have searched the existing issues before opening this issue.