Skip to content

Commit

Permalink
Merge pull request #78 from emirpprime/master
Browse files Browse the repository at this point in the history
Handle unavailable composer.json on private repo

Fixes #76
  • Loading branch information
schlessera authored Apr 19, 2018
2 parents 8002912 + 863abd4 commit 63bfef0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions features/package-install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1083,11 +1083,16 @@ Feature: Install WP-CLI packages

When I try `wp package install https://github.com/non-existent-git-user-asdfasdf/non-existent-git-repo-asdfasdf.git`
Then the return code should be 1
And STDERR should be:
And STDERR should contain:
"""
Error: Couldn't download composer.json file from 'https://raw.githubusercontent.com/non-existent-git-user-asdfasdf/non-existent-git-repo-asdfasdf/master/composer.json' (HTTP code 404).
Warning: Couldn't download composer.json file from 'https://raw.githubusercontent.com/non-existent-git-user-asdfasdf/non-existent-git-repo-asdfasdf/master/composer.json' (HTTP code 404). Presuming package name is 'non-existent-git-repo-asdfasdf'.
"""

When I try `wp package install https://github.com/wp-cli-tests/private-repository.git`
Then STDERR should contain:
"""
Warning: Couldn't download composer.json file from 'https://raw.githubusercontent.com/wp-cli-tests/private-repository/master/composer.json' (HTTP code 404). Presuming package name is 'private-repository'.
"""
And STDOUT should be empty

When I try `wp package install non-existent-git-user-asdfasdf/non-existent-git-repo-asdfasdf`
Then the return code should be 1
Expand Down
6 changes: 5 additions & 1 deletion src/Package_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,11 @@ private function check_git_package_name( $package_name, $version = '' ) {

$response = WP_CLI\Utils\http_request( 'GET', $raw_content_url, null /*data*/, $headers );
if ( 20 != substr( $response->status_code, 0, 2 ) ) {
WP_CLI::error( sprintf( "Couldn't download composer.json file from '%s' (HTTP code %d).", $raw_content_url, $response->status_code ) );
// Could not get composer.json. Possibly private so warn and return best guess from input (always xxx/xxx).
$package_name = explode( '/', $package_name );
$package_name = $package_name[1];
WP_CLI::warning( sprintf( "Couldn't download composer.json file from '%s' (HTTP code %d). Presuming package name is '%s'.", $raw_content_url, $response->status_code, $package_name ) );
return $package_name;
}

// Convert composer.json JSON to Array.
Expand Down

0 comments on commit 63bfef0

Please sign in to comment.