utils/maintenance/GitHub.php
public static function request(
		$url,
		$args = [],
		$headers = []
	) {
		$headers = array_merge(
			$headers,
			[
				'Accept'     => 'application/vnd.github.v3+json',
				'User-Agent' => 'WP-CLI',
			]
		);

		$token = getenv( 'GITHUB_TOKEN' );
		if ( $token ) {
			$headers['Authorization'] = 'token ' . $token;
		}

		$verb = 'GET';
		if ( isset( $headers['http_verb'] ) ) {
			$verb = $headers['http_verb'];
			unset( $headers['http_verb'] );
		}

		if ( 'POST' === $verb ) {
			$args = json_encode( $args );
		}

		$response = Utils\http_request( $verb, $url, $args, $headers );

		if ( 20 !== (int) substr( $response->status_code, 0, 2 ) ) {
			if ( isset( $args['throw_errors'] ) && false === $args['throw_errors'] ) {
				return false;
			}

			WP_CLI::error(
				sprintf(
					"Failed request to $url\nGitHub API returned: %s (HTTP code %d)",
					$response->body,
					$response->status_code
				)
			);
		}

		return [ json_decode( $response->body ), $response->headers ];
	}
public static function request(
		$url,
		$args = [],
		$headers = []
	) {
		$headers = array_merge(
			$headers,
			[
				'Accept'     => 'application/vnd.github.v3+json',
				'User-Agent' => 'WP-CLI',
			]
		);

		$token = getenv( 'GITHUB_TOKEN' );
		if ( $token ) {
			$headers['Authorization'] = 'token ' . $token;
		}

		$verb = 'GET';
		if ( isset( $headers['http_verb'] ) ) {
			$verb = $headers['http_verb'];
			unset( $headers['http_verb'] );
		}

		if ( 'POST' === $verb ) {
			$args = json_encode( $args );
		}

		$response = Utils\http_request( $verb, $url, $args, $headers );

		if ( 20 !== (int) substr( $response->status_code, 0, 2 ) ) {
			if ( isset( $args['throw_errors'] ) && false === $args['throw_errors'] ) {
				return false;
			}

			WP_CLI::error(
				sprintf(
					"Failed request to $url\nGitHub API returned: %s (HTTP code %d)",
					$response->body,
					$response->status_code
				)
			);
		}

		return [ json_decode( $response->body ), $response->headers ];
	}
public static function request ( $ url , $ args = [ ] , $ headers = [ ] ) { $ headers = array_merge ( $ headers , [ 'Accept' => 'application/vnd.github.v3+json' , 'User-Agent' => 'WP-CLI' , ] ) ; $ token = getenv ( 'GITHUB_TOKEN' ) ; if ( $ token ) { $ headers [ 'Authorization' ] = 'token ' . $ token ; } $ verb = 'GET' ; if ( isset ( $ headers [ 'http_verb' ] ) ) { $ verb = $ headers [ 'http_verb' ] ; unset ( $ headers [ 'http_verb' ] ) ; } if ( 'POST' === $ verb ) { $ args = json_encode ( $ args ) ; } $ response = Utils \ http_request ( $ verb , $ url , $ args , $ headers ) ; if ( 20 !== ( int ) substr ( $ response -> status_code , 0 , 2 ) ) { if ( isset ( $ args [ 'throw_errors' ] ) && false === $ args [ 'throw_errors' ] ) { return false ; } WP_CLI :: error ( sprintf ( "Failed request to $url\nGitHub API returned: %s (HTTP code %d)" , $ response -> body , $ response -> status_code ) ) ; } return [ json_decode ( $ response -> body ) , $ response -> headers ] ; }
Makes a request to the GitHub API.

@param string $url
@param array  $args
@param array  $headers

@return array|false
Makes a request to the GitHub API .