in src/shipit/ShipItGitHubUtils.php [129:194]
final public static async function makeAPIRequest(
ShipItGitHubCredentials $credentials,
string $path,
): Awaitable<vec<string>> {
$results = vec[];
$request_headers = vec[
'Accept: application/vnd.github.v3.patch',
];
$access_token = $credentials['access_token'];
$use_oauth = $access_token !== null;
if ($use_oauth) {
$request_headers[] =
Str\format('Authorization: token %s', $access_token ?? 'null');
}
$url = Str\format('https://api.github.com%s', $path);
while ($url !== null) {
$ch = PHP\curl_init($url);
PHP\curl_setopt($ch, \CURLOPT_USERAGENT, 'Facebook/ShipIt');
PHP\curl_setopt($ch, \CURLOPT_HTTPHEADER, $request_headers);
if (!$use_oauth) {
PHP\curl_setopt(
$ch,
\CURLOPT_USERPWD,
Str\format(
'%s:%s',
$credentials['user'] ?? 'null',
$credentials['password'] ?? 'null',
),
);
}
PHP\curl_setopt($ch, \CURLOPT_HEADER, 1);
/* @lint-ignore AWAIT_IN_LOOP Intentional serial await */
$response = await \HH\Asio\curl_exec($ch);
$header_len = PHP\curl_getinfo($ch, \CURLINFO_HEADER_SIZE);
$response_header = Str\slice($response, 0, $header_len);
$results[] = Str\slice($response, $header_len);
$url = null;
foreach (Str\split(Str\trim($response_header), "\n") as $header_line) {
if (Str\slice($header_line, 0, 5) === 'HTTP/') {
continue;
}
$sep = Str\search($header_line, ':');
if ($sep === null) {
continue;
}
$name = Str\lowercase(Str\slice($header_line, 0, $sep));
if ($name === 'link') {
$matches = Regex\first_match(
$header_line,
re"@<(?<next>https://api.github.com[^>]+)>; rel=\"next\"@",
);
if ($matches !== null) {
$url = $matches['next'];
break;
}
}
}
}
return $results;
}