1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Biurad opensource projects. |
5
|
|
|
* |
6
|
|
|
* @copyright 2022 Biurad Group (https://biurad.com/) |
7
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Biurad\Git; |
14
|
|
|
|
15
|
|
|
use Symfony\Component\Process\Exception\ExceptionInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Represents a git tag object. |
19
|
|
|
* |
20
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Tag extends Revision |
23
|
|
|
{ |
24
|
|
|
public function isAnnotated(): bool |
25
|
|
|
{ |
26
|
|
|
try { |
27
|
|
|
$tag = $this->repository->run('cat-file', ['tag', $this->revision]); |
28
|
|
|
} catch (ExceptionInterface) { |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return null !== ($tag ?? null); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param null|int $offset Start listing from a given position |
36
|
|
|
* @param null|int $limit Limit the fetched number of commits |
37
|
|
|
* |
38
|
|
|
* @return array<int,Commit> |
39
|
|
|
*/ |
40
|
|
|
public function getCommits(int $offset = null, int $limit = null): array |
41
|
|
|
{ |
42
|
|
|
return $this->repository->getLog($this->getName(), null, $offset, $limit)->getCommits(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function doName(): string |
46
|
|
|
{ |
47
|
|
|
if (\str_starts_with($ref = $this->revision, 'refs/tags/')) { |
48
|
|
|
return \substr($this->revision, 10); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Maybe we should throw an exception here? I'm not sure. |
52
|
|
|
$this->revision = 'refs/tags/'.$this->revision; |
53
|
|
|
|
54
|
|
|
return $ref; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|