diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..c382d69 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,22 @@ +# release.yml + +changelog: + categories: + - title: '🚀 New Features' + labels: + - 'type:new feature' + - title: '🔬 Improvements' + labels: + - 'type:improvement' + - title: '🐞 Bug Fixes' + labels: + - 'type:bug' + - title: '⬆️ Dependency Updates' + labels: + - 'type:dependencies' + - title: '⛔️ Security' + labels: + - 'type:security' + - title: '👻 Internal changes' + labels: + - 'type:internal' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0bc2ecb..7519e97 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: - "--prefer-lowest" steps: - name: Checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - name: Validate composer.json and composer.lock run: composer validate diff --git a/.github/workflows/label-verify.yml b/.github/workflows/label-verify.yml new file mode 100644 index 0000000..7c7efbc --- /dev/null +++ b/.github/workflows/label-verify.yml @@ -0,0 +1,20 @@ +name: "Verify type labels" + +on: + pull_request_target: + types: [opened, labeled, unlabeled, synchronize] + +jobs: + triage: + runs-on: ubuntu-latest + steps: + - uses: baev/action-label-verify@main + with: + allowed: | + type:bug + type:improvement + type:internal + type:invalid + type:new feature + type:dependencies + type:security diff --git a/composer.json b/composer.json index 8eb08e3..8637452 100644 --- a/composer.json +++ b/composer.json @@ -35,9 +35,9 @@ }, "require-dev": { "jetbrains/phpstorm-attributes": "^1", - "phpunit/phpunit": "^9.5.9", + "phpunit/phpunit": "^9.5.10", "psalm/plugin-phpunit": "^0.16.1", - "squizlabs/php_codesniffer": "^3.6", + "squizlabs/php_codesniffer": "^3.6.1", "vimeo/psalm": "^4.10" }, "autoload": { diff --git a/src/Allure.php b/src/Allure.php index 79705af..3603a80 100644 --- a/src/Allure.php +++ b/src/Allure.php @@ -19,7 +19,6 @@ use Qameta\Allure\Model\LinkType; use Qameta\Allure\Model\Parameter; use Qameta\Allure\Model\ParameterMode; -use Qameta\Allure\Model\ResultFactoryInterface; use Qameta\Allure\Model\Severity; use Qameta\Allure\Model\Status; use Qameta\Allure\Model\StepResult; @@ -28,7 +27,6 @@ use Qameta\Allure\Setup\LifecycleConfigInterface; use Qameta\Allure\Setup\LifecycleConfiguratorInterface; use Qameta\Allure\Setup\LifecycleFactoryInterface; -use Qameta\Allure\Setup\StatusDetectorInterface; use ReflectionException; use ReflectionFunction; use ReflectionMethod; @@ -72,14 +70,9 @@ public static function getLifecycleConfigurator(): LifecycleConfiguratorInterfac return self::getInstance()->getLifecycleBuilder(); } - public static function getResultFactory(): ResultFactoryInterface + public static function getConfig(): LifecycleConfigInterface { - return self::getInstance()->getLifecycleConfig()->getResultFactory(); - } - - public static function getStatusDetector(): StatusDetectorInterface - { - return self::getInstance()->getLifecycleConfig()->getStatusDetector(); + return self::getInstance()->getLifecycleConfig(); } /** @@ -239,12 +232,30 @@ public static function parameter( public static function issue(string $name, ?string $url = null): void { - self::getInstance()->doLink(Link::issue($name, $url)); + self::getInstance()->doLink( + Link::issue( + $name, + $url ?? self::getInstance() + ->getLifecycleConfig() + ->getLinkTemplates() + ->get(LinkType::issue()) + ?->buildUrl($name), + ), + ); } public static function tms(string $name, ?string $url = null): void { - self::getInstance()->doLink(Link::tms($name, $url)); + self::getInstance()->doLink( + Link::tms( + $name, + $url ?? self::getInstance() + ->getLifecycleConfig() + ->getLinkTemplates() + ->get(LinkType::tms()) + ?->buildUrl($name), + ), + ); } public static function link(string $url, ?string $name = null, ?LinkType $type = null): void @@ -414,7 +425,7 @@ private function readCallableAttributes(callable $callable): AttributeParser $attributes = $attributeReader->getFunctionAnnotations(new ReflectionFunction($callable)); } - return new AttributeParser($attributes); + return new AttributeParser($attributes, $this->getLifecycleConfig()->getLinkTemplates()); } private function doLabel(Label $label): void diff --git a/src/Attribute/AttributeParser.php b/src/Attribute/AttributeParser.php index eaca048..ae590cb 100644 --- a/src/Attribute/AttributeParser.php +++ b/src/Attribute/AttributeParser.php @@ -9,6 +9,8 @@ use Qameta\Allure\Exception\InvalidMethodNameException; use Qameta\Allure\Model; use Qameta\Allure\Model\ModelProviderInterface; +use Qameta\Allure\Setup\LinkTemplateCollection; +use Qameta\Allure\Setup\LinkTemplateCollectionInterface; use ReflectionClass; use ReflectionException; use ReflectionFunction; @@ -18,8 +20,9 @@ use function array_merge; use function is_string; -class AttributeParser implements ModelProviderInterface +final class AttributeParser implements ModelProviderInterface { + use Model\ModelProviderTrait; private ?string $displayName = null; @@ -43,12 +46,12 @@ class AttributeParser implements ModelProviderInterface private array $parameters = []; /** - * @param array $attributes - * @param array $linkTemplates + * @param array $attributes + * @param LinkTemplateCollectionInterface $linkTemplates */ public function __construct( array $attributes, - private array $linkTemplates = [], + private LinkTemplateCollectionInterface $linkTemplates, ) { $this->processAnnotations(...$attributes); } @@ -57,7 +60,7 @@ public function __construct( * @param class-string|object|null $classOrObject * @param callable-string|Closure|null $methodOrFunction * @param string|null $property - * @param array $linkTemplates + * @param LinkTemplateCollectionInterface|null $linkTemplates * @return list * @throws ReflectionException */ @@ -65,7 +68,7 @@ public static function createForChain( string|object|null $classOrObject, string|Closure|null $methodOrFunction = null, ?string $property = null, - array $linkTemplates = [], + ?LinkTemplateCollectionInterface $linkTemplates = null, ): array { $reader = new LegacyAttributeReader( new AnnotationReader(), @@ -96,7 +99,7 @@ public static function createForChain( return [ new self( array_merge(...$annotations), - $linkTemplates, + $linkTemplates ?? new LinkTemplateCollection(), ) ]; } @@ -128,22 +131,15 @@ private function processAnnotations(AttributeInterface ...$attributes): void private function createLink(LinkInterface $link): Model\Link { - $linkType = $link->getType(); + $linkType = Model\LinkType::fromOptionalString($link->getType()); return new Model\Link( name: $link->getName(), - url: $link->getUrl() ?? $this->getLinkUrl($link->getName(), $linkType), - type: Model\LinkType::fromOptionalString($linkType), + url: $link->getUrl() ?? $this->linkTemplates->get($linkType)?->buildUrl($link->getName()), + type: $linkType, ); } - private function getLinkUrl(?string $name, ?string $type): ?string - { - return isset($type, $this->linkTemplates[$type]) - ? $this->linkTemplates[$type]->buildUrl($name) - : $name; - } - /** * @return list */ @@ -186,14 +182,6 @@ public function getParameters(): array return $this->parameters; } - /** - * @deprecated Please use {@see getDisplayName()} method. - */ - public function getTitle(): ?string - { - return $this->getDisplayName(); - } - public function getDisplayName(): ?string { return $this->displayName; diff --git a/src/Attribute/LinkTemplateInterface.php b/src/Attribute/LinkTemplateInterface.php deleted file mode 100644 index b33a890..0000000 --- a/src/Attribute/LinkTemplateInterface.php +++ /dev/null @@ -1,11 +0,0 @@ - + */ + private array $linkTemplates = []; + + private ?LinkTemplateCollectionInterface $linkTemplateCollection = null; + private ?StatusDetectorInterface $statusDetector = null; public function createLifecycle(ResultsWriterInterface $resultsWriter): AllureLifecycleInterface @@ -84,6 +96,18 @@ public function addHooks( return $this; } + public function addLinkTemplate(LinkType $type, LinkTemplateInterface $template): LifecycleConfiguratorInterface + { + $this->linkTemplates[(string) $type] = $template; + + return $this; + } + + public function getLinkTemplates(): LinkTemplateCollectionInterface + { + return $this->linkTemplateCollection ??= new LinkTemplateCollection($this->linkTemplates); + } + public function setStatusDetector(StatusDetectorInterface $statusDetector): self { $this->statusDetector = $statusDetector; diff --git a/src/Model/ModelProviderChain.php b/src/Model/ModelProviderChain.php index 4f0615b..610b040 100644 --- a/src/Model/ModelProviderChain.php +++ b/src/Model/ModelProviderChain.php @@ -100,4 +100,14 @@ public function getDescriptionHtml(): ?string return $descriptionHtml; } + + public function getFullName(): ?string + { + $fullName = null; + foreach ($this->providers as $provider) { + $fullName ??= $provider->getFullName(); + } + + return $fullName; + } } diff --git a/src/Model/ModelProviderInterface.php b/src/Model/ModelProviderInterface.php index 1aca060..1a8109b 100644 --- a/src/Model/ModelProviderInterface.php +++ b/src/Model/ModelProviderInterface.php @@ -22,14 +22,11 @@ public function getLabels(): array; */ public function getParameters(): array; - /** - * @deprecated Please use {@see getDisplayName()} method. - */ - public function getTitle(): ?string; - public function getDisplayName(): ?string; public function getDescription(): ?string; public function getDescriptionHtml(): ?string; + + public function getFullName(): ?string; } diff --git a/src/Model/ModelProviderTrait.php b/src/Model/ModelProviderTrait.php new file mode 100644 index 0000000..8d0751b --- /dev/null +++ b/src/Model/ModelProviderTrait.php @@ -0,0 +1,53 @@ + + */ + public function getLinks(): array + { + return []; + } + + /** + * @return list