|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the Gitlab API library. |
| 7 | + * |
| 8 | + * (c) Matt Humphrey <matth@windsor-telecom.co.uk> |
| 9 | + * (c) Graham Campbell <hello@gjcampbell.co.uk> |
| 10 | + * |
| 11 | + * For the full copyright and license information, please view the LICENSE |
| 12 | + * file that was distributed with this source code. |
| 13 | + */ |
| 14 | + |
| 15 | +namespace Gitlab\Api; |
| 16 | + |
| 17 | +use Symfony\Component\OptionsResolver\Options; |
| 18 | +use Symfony\Component\OptionsResolver\OptionsResolver; |
| 19 | + |
| 20 | +class Registry extends AbstractApi |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @param array $parameters { |
| 24 | + * |
| 25 | + * @var bool $tags include an array of tags in the response |
| 26 | + * @var bool $tags_count include tags_count in the response |
| 27 | + * @var bool $size include the deduplicated size in the response |
| 28 | + * } |
| 29 | + */ |
| 30 | + public function repository(int|string $repository_id, array $parameters = []): mixed |
| 31 | + { |
| 32 | + $resolver = self::createRepositoryResolver(); |
| 33 | + |
| 34 | + return $this->get('registry/repositories/'.self::encodePath($repository_id), $resolver->resolve($parameters)); |
| 35 | + } |
| 36 | + |
| 37 | + public function removeRepository(int|string $project_id, int $repository_id): mixed |
| 38 | + { |
| 39 | + return $this->delete($this->getProjectPath($project_id, 'registry/repositories/'.self::encodePath($repository_id))); |
| 40 | + } |
| 41 | + |
| 42 | + public function repositoryTags(int|string $project_id, int $repository_id, array $parameters = []): mixed |
| 43 | + { |
| 44 | + $resolver = $this->createOptionsResolver(); |
| 45 | + |
| 46 | + return $this->get( |
| 47 | + $this->getProjectPath($project_id, 'registry/repositories/'.self::encodePath($repository_id).'/tags'), |
| 48 | + $resolver->resolve($parameters) |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + public function repositoryTag(int|string $project_id, int $repository_id, string $tag_name): mixed |
| 53 | + { |
| 54 | + return $this->get($this->getProjectPath( |
| 55 | + $project_id, |
| 56 | + 'registry/repositories/'.self::encodePath($repository_id).'/tags/'.self::encodePath($tag_name) |
| 57 | + )); |
| 58 | + } |
| 59 | + |
| 60 | + public function removeRepositoryTag(int|string $project_id, int $repository_id, string $tag_name): mixed |
| 61 | + { |
| 62 | + return $this->delete($this->getProjectPath( |
| 63 | + $project_id, |
| 64 | + 'registry/repositories/'.self::encodePath($repository_id).'/tags/'.self::encodePath($tag_name) |
| 65 | + )); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @param array $parameters { |
| 70 | + * |
| 71 | + * @var string $name_regex_delete regex of tag names to delete |
| 72 | + * @var string $name_regex_keep regex of tag names to keep |
| 73 | + * @var int $keep_n number of latest matching tags to keep |
| 74 | + * @var string $older_than delete tags older than this human-readable duration |
| 75 | + * } |
| 76 | + */ |
| 77 | + public function removeRepositoryTags(int|string $project_id, int $repository_id, array $parameters): mixed |
| 78 | + { |
| 79 | + $resolver = new OptionsResolver(); |
| 80 | + $resolver->setRequired('name_regex_delete') |
| 81 | + ->setAllowedTypes('name_regex_delete', 'string') |
| 82 | + ; |
| 83 | + $resolver->setDefined('name_regex_keep') |
| 84 | + ->setAllowedTypes('name_regex_keep', 'string') |
| 85 | + ; |
| 86 | + $resolver->setDefined('keep_n') |
| 87 | + ->setAllowedTypes('keep_n', 'int') |
| 88 | + ; |
| 89 | + $resolver->setDefined('older_than') |
| 90 | + ->setAllowedTypes('older_than', 'string') |
| 91 | + ; |
| 92 | + |
| 93 | + return $this->delete( |
| 94 | + $this->getProjectPath($project_id, 'registry/repositories/'.self::encodePath($repository_id).'/tags'), |
| 95 | + $resolver->resolve($parameters) |
| 96 | + ); |
| 97 | + } |
| 98 | + |
| 99 | + private static function createRepositoryResolver(): OptionsResolver |
| 100 | + { |
| 101 | + $resolver = new OptionsResolver(); |
| 102 | + $booleanNormalizer = function (Options $resolver, $value): string { |
| 103 | + return $value ? 'true' : 'false'; |
| 104 | + }; |
| 105 | + |
| 106 | + $resolver->setDefined('tags') |
| 107 | + ->setAllowedTypes('tags', 'bool') |
| 108 | + ->setNormalizer('tags', $booleanNormalizer) |
| 109 | + ; |
| 110 | + $resolver->setDefined('tags_count') |
| 111 | + ->setAllowedTypes('tags_count', 'bool') |
| 112 | + ->setNormalizer('tags_count', $booleanNormalizer) |
| 113 | + ; |
| 114 | + $resolver->setDefined('size') |
| 115 | + ->setAllowedTypes('size', 'bool') |
| 116 | + ->setNormalizer('size', $booleanNormalizer) |
| 117 | + ; |
| 118 | + |
| 119 | + return $resolver; |
| 120 | + } |
| 121 | +} |
0 commit comments