Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Package_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function install( $args, $assoc_args ) {
'insecure' => $insecure,
];
$gitlab_token = getenv( 'GITLAB_TOKEN' ); // Use GITLAB_TOKEN if available to avoid authorization failures or rate-limiting.
$headers = $gitlab_token && strpos( $package_name, '://gitlab.com/' ) !== false ? [ 'PRIVATE-TOKEN' => $gitlab_token ] : [];
$headers = $gitlab_token && 'gitlab.com' === strtolower( (string) Utils\parse_url( $package_name, PHP_URL_HOST ) ) ? [ 'PRIVATE-TOKEN' => $gitlab_token ] : [];
$response = Utils\http_request( 'GET', $package_name, null, $headers, $options );
if ( 20 !== (int) substr( (string) $response->status_code, 0, 2 ) ) {
@unlink( $temp ); // @codingStandardsIgnoreLine
Expand Down Expand Up @@ -1115,8 +1115,7 @@ private function get_package_by_shortened_identifier( $package_name, $insecure =
// Fall back to GitLab URL if we had no match yet.
$url = "https://gitlab.com/{$package_name}.git";
$gitlab_token = getenv( 'GITLAB_TOKEN' ); // Use GITLAB_TOKEN if available to avoid authorization failures or rate-limiting.
$headers = $github_token ? [ 'Authorization' => 'token ' . $github_token ] : [];
$headers = $gitlab_token && strpos( $package_name, '://gitlab.com/' ) !== false ? [ 'PRIVATE-TOKEN' => $gitlab_token ] : [];
$headers = $gitlab_token ? [ 'PRIVATE-TOKEN' => $gitlab_token ] : [];
$response = Utils\http_request( 'GET', $url, null /*data*/, $headers, $options );
if ( 20 === (int) substr( (string) $response->status_code, 0, 2 ) ) {
return $url;
Expand Down Expand Up @@ -1467,7 +1466,7 @@ private function check_github_package_name( $package_name, $version = '', $insec
* to false.
*/
private function check_git_package_name( $package_name, $url = '', $version = '', $insecure = false ) {
if ( $url && ( ( strpos( $url, '://gitlab.com/' ) !== false ) || ( strpos( $url, 'git@gitlab.com:' ) !== false ) ) ) {
if ( $url && ( ( 'gitlab.com' === strtolower( (string) Utils\parse_url( $url, PHP_URL_HOST ) ) ) || ( 0 === strpos( $url, 'git@gitlab.com:' ) ) ) ) {
$matches = [];
preg_match( '#gitlab.com[:/](.*?)\.git#', $url, $matches );
return $this->check_gitlab_package_name( $matches[1], $version, $insecure );
Expand Down
Loading