From a7a4cd5799fc4d880f9171c5dc2f244f91b8cc69 Mon Sep 17 00:00:00 2001 From: Manish Songirkar Date: Wed, 2 Dec 2026 17:51:56 +0530 Subject: [PATCH] fix(package): include package name in default branch decode warning 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 #265 --- features/package-install.feature | 37 ++++++++++++++++++++++++++++++++ src/Package_Command.php | 7 +++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/features/package-install.feature b/features/package-install.feature index df00b828..086d3444 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -1447,6 +1447,43 @@ Feature: Install WP-CLI packages wp-cli/community-command """ + Scenario: Warn with the package name when the GitHub API response cannot be decoded + Given an empty directory + And a mock-github-api.php file: + """ + body ); if ( JSON_ERROR_NONE !== json_last_error() ) { - WP_CLI::warning( "Couldn't fetch default branch for package '%s' (failed to decode JSON response). Presuming default branch is 'master'." ); + WP_CLI::warning( + sprintf( + "Couldn't fetch default branch for package '%s' (failed to decode JSON response). Presuming default branch is 'master'.", + $package_name + ) + ); return 'master'; }