YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.21k stars 403 forks source link

'puc-github-http-error' Issue #559

Closed craigcallen closed 7 months ago

craigcallen commented 7 months ago

This error just started recently on all of our plugins and themes. They were working perfectly before and no changes in code on our end, but we cannot update anything remotely now. Please advise, thanks in advance for you help.

  1. GitHub API error. Base URL: "/repos/:user/:repo/branches/main", HTTP status code: 401. puc-github-http-error
  2. Could not retrieve version information from the repository. This usually means that the update checker either can't connect to the repository or it's configured incorrectly. puc-no-update-source

Also getting an error when I click the 'View details' of the plugin and it says it cannot be found.

Screenshot 2024-01-25 at 7 39 22 AM
YahnisElsts commented 7 months ago

A 401 means "unauthorized", so the first thing to check would be if your GitHub access token is still valid (assuming that it's a private repository). I believe at least some tokens expire automatically, and an expired token could cause updates to stop working without any code changes.

The "Plugin not found" error, on the other hand, would typically mean that the update checker is configured incorrectly, e.g. maybe the file name or slug passed to PUC is wrong. However, that's not the kind of error that would start happening suddenly without any code changes.

The "View details" screen shows an iframe with a URL similar to this: https://example.com/wp-admin/plugin-install.php?tab=plugin-information&plugin=plugin-slug-here&section=changelog

Take a look at the iframe URL for your plugin. Does the plugin query parameter match your plugin? If you're using a custom slug when initializing PUC, does it match that slug?

Finally, an unrelated thing that could cause this error is if PUC is not initialized during that request. Does the plugin only initialize the update checker under certain conditions?

craigcallen commented 7 months ago

I set my token to never expire, but will take a look at it and test a new key. Will keep you posted on results.

craigcallen commented 7 months ago

I set my token to never expire, but will take a look at it and test a new key. Will keep you posted on results.

Do I need a different token for each plugin or theme?

YahnisElsts commented 7 months ago

I think that's technically not necessary unless you're using fine-grained tokens that are restricted to only having access to specific repositories.

craigcallen commented 7 months ago

Is there documentation showing access token setup? I currently only have "repo" and all sub selections checked. Should I have more scopes added?

YahnisElsts commented 7 months ago

I have a couple of tokens myself, for testing purposes. For the classic token, I have all of the "repo" options enabled and also "workflow", but that one is probably unnecessary. For the fine-grained token, I've given it access to a specific repository and read-only access to "Contents" and "Metadata".

craigcallen commented 7 months ago

Here is some of my code below - I have a few characters removed the token for security reasons, but is there anything you notice here? I am at a complete loss.

<?php
/*
Plugin Name: My Website Custom Functions
Version: 1.0.2
Description: Custom functions built for Allen Media websites and PWA's.
Author: Craig Allen, Web Designer & Developer
Author URI: https://craigcallen.com
Plugin URI: https://github.com/craigcallen/my-website-functions-plugin/
*/

//require_once(plugin_dir_path(__FILE__) . '/includes/user-last-login.php');

//Plugin Verion update checker via Github
require 'plugin-update-checker/plugin-update-checker.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'https://github.com/craigcallen/my-website-functions-plugin/',
    __FILE__,
    'mywebsite-functions'
);

//Set the branch that contains the stable release.
$myUpdateChecker->setBranch('main');

//Optional: If you're using a private repository, specify the access token like this:
$myUpdateChecker->setAuthentication('ghp_tokenkey');
YahnisElsts commented 7 months ago

One thing I notice is that you seem to be using an old version of PUC. If it's anything older than 4.9 it's certain to have some GitHub-related bugs, and other 4.x releases also have known issues. I would recommend upgrading to the latest release (currently 5.3).

craigcallen commented 7 months ago

Noticed that after I sent in the message. Testing again this morning. Appreciate your help.

craigcallen commented 7 months ago

New errors - At first I was getting an archive error, so downgraded wordpress version to 6.4.2. Now I am getting more errors after updating to newest version:

Could not determine if updates are available for My Website Custom Functions.

I just added you to the repository - would you care to see what I am doing wrong? Doesn't seem like this should be this difficult.

YahnisElsts commented 7 months ago

I tried a few tests, and as far as I can tell, it is a bad access token. Try generating a new fine-grained token?

YahnisElsts commented 7 months ago

I already tried the above myself, but it appears that I can't generate a token for a repository that I do not own even if I technically have access. So I made a fork and generated a token for that repository. I replaced the repository URL and token in the code, and it works - no other code changes required: firefox_2024-02-02_16-45-16

craigcallen commented 7 months ago

That was it - greatly appreciate your time and assistance on this.