Repository navigation
fix(package): include package name in default branch decode warning - #266
Merged
swissspidy merged 1 commit intoDec 2, 2026
Conversation
The warning shown when the GitHub API response for a package's default branch cannot be decoded as JSON was a plain string with a "%s" placeholder, but it was never passed through sprintf(). WP_CLI::warning() does not format its message, so users saw a literal "%s" instead of the package name. Wrap the message in sprintf() with $package_name, the same way as the two sibling warnings in get_github_default_branch(). Add a behat scenario that answers api.github.com requests with a non-JSON body through a mock Requests transport (loaded with WP_CLI_REQUIRE, because "package" is a protected command that ignores --require) and asserts the package name is printed. The scenario fails without the fix. Fixes wp-cli#265
Contributor
|
Hello! 👋 Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project. Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation. Here are some useful Composer commands to get you started:
To run a single Behat test, you can use the following command: # Run all tests in a single file
composer behat features/some-feature.feature
# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123You can find a list of all available Behat steps in our handbook. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #265
What changed
src/Package_Command.php: inget_github_default_branch(), the warning for a GitHub API response that cannot be decoded as JSON is now wrapped insprintf()with$package_name. Before,WP_CLI::warning()received a string that still had a literal%s, and it does not format messages. The two sibling warnings in the same method already usesprintf( ..., $package_name ).features/package-install.feature: new scenario "Warn with the package name when the GitHub API response cannot be decoded".Why
wp package install https://github.com/<owner>/<repo>.gitprinted:A proxy or captive portal page that answers with HTTP 200 and a non-JSON body triggers this. Now it prints the package name, as in
'<owner>/<repo>'.About the test
Utils\http_request()against a hard-codedapi.github.comURL. So the scenario answers that request with a mockRequeststransport. The transport is set through thehttp_request_optionshook in amock-github-api.phpfile.WP_CLI_REQUIRE.packageis a protected command, so it ignores--require, but it does load files fromWP_CLI_REQUIRE.https://api.github.com/repos/are mocked. The rest of the install runs as in the existing "Try to install bad packages" scenario.STDERR should containstep. With the fix, it passes.Out of scope
master). This is unchanged.Test plan
Run locally with
WP_CLI_PHP_ARGScleared andGITHUB_TOKENset, so the@github-apiscenarios run too.vendor/bin/run-behat-tests(all feature files): 61 scenarios, 59 passed, 2 failed.package-install.feature:119) and "Install a package from the wp-cli package index with a mixed-case name" (package-install.feature:787). They install real third-party packages from GitHub.mainat6487f3a, so this change does not cause them.vendor/bin/run-php-unit-tests: 87 tests OK. The 1 PHPUnit deprecation is the same without this change.phpcsonsrcandfeatures,parallel-lint src,phpstan analyse: no errors.wp package installagainst a local mock ofapi.github.com(HTTP 200, bodynot json). The warning shows'example/some-pkg'instead of'%s'.--insecureretry path. My local TLS mock failed on its self-signed certificate before the changed code ran. The changed branch runs after the response body is received, so it does not depend on--insecure.