YahnisElsts/plugin-update-checker

enableReleaseAssets() no longer the supported method

Narimm opened this issue · 5 comments

In the README.md the above code is still the recommended way to enable github release. However as you pointed out it no longer exists in the VCS Api and while I know if the plugin coder is sure he is using github he can still call it. IDE's hate it and its poor coding practice as it requires a virtually unchecked cast

Should the readme say

use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
use YahnisElsts\PluginUpdateChecker\v5p1\Vcs\Api;
$myUpdateChecker->getVcsApi()->setStrategyFilterName(Api::STRATEGY_LATEST_RELEASE);

There is no enableReleaseStrategy() method and the readme doesn't mention it. Did you mean enableReleaseAssets()? Also, setStrategyFilterName() is mainly intended for internal use, it accepts a filter name not one of the STRATEGY_... constants, and you normally don't need to call it unless you want to use a custom filter name (not the same as a custom filter) for some reason.

If you want to be explicit about calling enableReleaseAssets(), you could directly construct a GitHubApi or a GitLabApi instance and then pass it to the Vcs\PluginUpdateChecker constructor. It's more complex than just calling buildUpdateChecker(), but it provides more control and should satisfy the IDE.

My aplogies I did mean

$myUpdateChecker = PucFactory::buildUpdateChecker('@plugin.github_repo@/releases/latest/download/info.json', __FILE__, '/@plugin.slug@');
    $myUpdateChecker->getVcsApi()->enableReleaseAssets();

Above is how we used to enable a release strategy prior to v5 using Github.
Its no longer possible because the function was removed from the API. As you mentioned its available in some API's but not all.

As I mentioned, if you want to be explicit about it, you could construct an API instance directly. For example:

$githubApiInstance = new \YahnisElsts\PluginUpdateChecker\v5p1\Vcs\GitHubApi(
	'https://github.com/username/repository',
	'access-token-here'
);
$githubApiInstance->enableReleaseAssets();

$updateChecker = new \YahnisElsts\PluginUpdateChecker\v5p1\Vcs\PluginUpdateChecker(
	$githubApiInstance,
	__FILE__,
	'plugin-slug-here'
);

What should I review about that screenshot? That code will still work as long as you're using a GitHub repository.

It works fine, the way I use it (for my plugin):

// include our custom update checker code
require_once 'plugin-update-checker/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
        'https://github.com/liedekef/events-made-easy/',
        __FILE__,
        'events-made-easy'
);
// we'll use a release asset
$myUpdateChecker->getVcsApi()->enableReleaseAssets('/events-made-easy\.zip/');