mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 21:04:52 +08:00
* Update test-extensions.php * Enable UPX test * Add debug messages * Test * Revert * Update tests.yml * Update tests.yml * Explict define GITHUB_TOKEN * What's this??? * Check GITHUB_TOKEN in workflow * Test token variable in step * Test token variable inside php * Test token in command * Get env in commands * Revert workflow env, add passthrough GITHUB_TOKEN into docker * See build commands * See build commands * Typo fix * Remove debug symbol for normal mode
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace SPC\store;
|
|
|
|
class CurlHook
|
|
{
|
|
/**
|
|
* 执行 GitHub Token 的 Curl 头添加
|
|
*
|
|
* @param string $method 修改的 method
|
|
* @param string $url 修改的链接
|
|
* @param array $headers 修改的 headers
|
|
*/
|
|
public static function setupGithubToken(string $method, string $url, array &$headers): void
|
|
{
|
|
$token = getenv('GITHUB_TOKEN');
|
|
if (!$token) {
|
|
logger()->debug('no github token found, skip');
|
|
return;
|
|
}
|
|
if (getenv('GITHUB_USER')) {
|
|
$auth = base64_encode(getenv('GITHUB_USER') . ':' . $token);
|
|
$he = "Authorization: Basic {$auth}";
|
|
if (!in_array($he, $headers)) {
|
|
$headers[] = $he;
|
|
}
|
|
logger()->info("using basic github token for {$method} {$url}");
|
|
} else {
|
|
$auth = $token;
|
|
$he = "Authorization: Bearer {$auth}";
|
|
if (!in_array($he, $headers)) {
|
|
$headers[] = $he;
|
|
}
|
|
logger()->info("using bearer github token for {$method} {$url}");
|
|
}
|
|
}
|
|
}
|