Closed jihaisse closed 1 year ago
Could you elaborate on the intent of this change? The code itself looks relatively simple, but I'm not sure I fully understand what goal it's trying to accomplish.
By the way, the "latest release" endpoint of the GitHub API specifically does not return pre-releases, so this approach might not work with that.
Yes of course !
For example, let's say we have a dev environment, a staging and a prod environment.
In my Gitlab, I could have a main branch, a dev branch and a staging branch. The main is for the prod, dev for dev and staging for staging.
With Gitlab I've made a CI uising semantic-release, so when I push on the main branch, it make a release with the version number updated, for example 1.1.0.
I've got the same with the staging branch, and the release will be 1.1.0-staging.1
So, in my plugin, I check if I am on local / dev or staging or production, for example with the domain name.
This way, I can filter on the release name and PUC will give me the latest release I want depending of the environment.
So if I'm in staging, I will configure PUC with : $myUpdateChecker->getVcsApi()->filterPrereleaseName('staging');
If I am in production, I have no configuration to make, and PUC will return the latest release that match exactly the version number x.x.x (the second regex)
And if I am in local or in dev, I can use a branch.
Let me know if I am not clear enough.
OK for GitHub, I wasn't aware of that, I saw the line on the code but didn't noticed it. I remember that I was looking for a such flag in GitLab but without success.
Thank you for the additional details. Given this, I have two issues with the proposed implementation:
filterPrereleaseName()
promises too much. It suggests that the update checker will try to filter prereleases, but what it really does is mostly just a regex match on the tag name. To put it another way, the intent is to filter prereleases, but depending on what the user passes to the function, that might not be what actually happens. This could be confusing for people.I've added setReleaseVersionFilter()
and setReleaseFilter()
methods that implement these ideas. Here's an example:
//Allow only beta versions (e.g. for testing).
$updateChecker->getVcsApi()->setReleaseVersionFilter(
'/beta/i', //Regex for the version number.
Api::RELEASE_FILTER_ALL, //Optional. Disables the default filter that normally removes prereleases.
30 //Optional. Max number of recent releases to scan for matches.
);
Hello, thanks for the update.
I have a strange behavior now, the link "check for updates" is missing in the UI. And PUC doesn't detect any new release or update from the main branch
What exactly do you mean by "missing the UI"? Also, is this happening with just the patch, or have you actually added a custom filter?
If "missing the UI" means that there's a blank page somewhere, that could indicate a PHP error. Please check the PHP error log for recent errors.
I have removed all filters to have something like this, and only this :
new GitLabApi(
'https://gitlab.example.com/wordpress/plugins/mon-plugin/',
'glpat-xxxxxx',
'plugins'
),
__FILE__,
'mon-plugin'
);
So in the plugins page, in the metabox of the plugin the link to force a check for an update is missing.
In the screenshot, it looks like the plugin is inactive. Is the code that sets up the update checker inside the plugin? In that case, it won't work unless the plugin is active. The update checker can't display the "check for updates" link if the code isn't actually running.
OK, my bad ! I've spend one hour on this 😅
I've tried with the setReleaseVersionFilter()
it's working like a charm.
I have a warning in my IDE : Method 'setReleaseVersionFilter' not found in YahnisElsts\PluginUpdateChecker\v5p0\Vcs\Api when I call $myUpdateChecker->getVcsApi()->setReleaseVersionFilter()
If you know how to resolve this.
Thanks for the job !
This might vary depending on the IDE, but I think it's probably because the Api
base class does not have this method, only some of the subclasses do. I didn't add it to the base class because some APIs integrations (currently BitBucket) don't support releases or release filters.
OK, thanks ! I think this pull request can be closed now.
All right, I am closing the PR.
With this, you can filter on prerelease for example :
$myUpdateChecker->getVcsApi()->filterPrereleaseName('beta');
Will return only the last release with semver like "1.0.0-beta.1"
It's just a proposal, I'm not sure you will include this like that, the code may be improved.