Lines
71.42%
5 / 7
Methods
50.00%
1 / 2
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| findRunningCommit | 66.66% | 4 / 6 | 0.00% | 0 / 1 | 4.59 | ||
| 10 | final readonly class RunningReleaseDetector | |
| 11 | { | |
| 12 | private const string RELEASES_DIRECTORY = 'releases'; | |
| 13 | ||
| 14 | private const string CURRENT_RELEASE_LINK = 'current'; | |
| 15 | ||
| 16 | public function __construct(private ProjectRoot $projectRoot) {} | |
| 17 | ||
| 18 | // The entrypoint runs a release from <app>/releases/<commit>, with <app>/current pointing at it. | |
| 19 | public function findRunningCommit(): ?CommitId | |
| 20 | { | |
| 21 | $releasesDirectory = \dirname($this->projectRoot->path); | |
| 22 | ||
| 23 | if (basename($releasesDirectory) !== self::RELEASES_DIRECTORY || !is_link(\dirname($releasesDirectory) . '/' . self::CURRENT_RELEASE_LINK)) { | |
| 24 | return null; | |
| 25 | } | |
| 26 | ||
| 27 | try { | |
| 28 | return new CommitId(basename($this->projectRoot->path)); | |
| 29 | } catch (DeployException) { | |
| 30 | return null; | |
| 31 | } | |
| 32 | } | |
| 33 | } |