mirror of
https://github.com/pestphp/pest.git
synced 2026-12-06 07:42:17 +01:00
7cdebc6a95
* refactor: extract shared CI detection utility Consolidate duplicated CI environment detection logic from Snapshot and BaselineSync into a shared Pest\Support\Ci class. This reduces duplication and provides a single source of truth for CI detection, including comprehensive environment variable checks for all major CI providers. * fix(tia): persist state on detached HEAD Allow detached checkouts to write, delete, and rebuild TIA state so baseline publishers and local detached workflows produce a usable graph. Resolve the writable baseline from the Git branch, CI branch metadata, or a stable workspace key. Keep the default branch as the read fallback so local workspaces can use a published baseline without changing it.
47 lines
1011 B
PHP
47 lines
1011 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pest\Plugins\Tia\Cis;
|
|
|
|
use Pest\Plugins\Tia\Cis\Concerns\ReadsEnvironment;
|
|
use Pest\Plugins\Tia\Contracts\Ci;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
final readonly class GitHub implements Ci
|
|
{
|
|
use ReadsEnvironment;
|
|
|
|
public function currentBranch(): ?string
|
|
{
|
|
return $this->environment('GITHUB_REF_NAME');
|
|
}
|
|
|
|
public function defaultBranch(): ?string
|
|
{
|
|
$path = $this->environment('GITHUB_EVENT_PATH');
|
|
|
|
if ($path === null || ! is_file($path) || ! is_readable($path)) {
|
|
return null;
|
|
}
|
|
|
|
$contents = @file_get_contents($path);
|
|
|
|
if ($contents === false) {
|
|
return null;
|
|
}
|
|
|
|
$payload = json_decode($contents, true);
|
|
|
|
if (! is_array($payload) || ! is_array($payload['repository'] ?? null)) {
|
|
return null;
|
|
}
|
|
|
|
$branch = $payload['repository']['default_branch'] ?? null;
|
|
|
|
return is_string($branch) && $branch !== '' ? $branch : null;
|
|
}
|
|
}
|