From 1725b7677c773ac3383254767959c01052e0414b Mon Sep 17 00:00:00 2001 From: nikita tarasov Date: Thu, 12 Dec 2024 16:14:43 +0300 Subject: [PATCH] Add composer audit abandoned behavior --- doc/tasks/securitychecker/composeraudit.md | 7 +++++++ src/Task/SecurityCheckerComposeraudit.php | 3 +++ .../Unit/Task/SecurityCheckerComposerauditTest.php | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/doc/tasks/securitychecker/composeraudit.md b/doc/tasks/securitychecker/composeraudit.md index 0da96d56..7a88c55d 100644 --- a/doc/tasks/securitychecker/composeraudit.md +++ b/doc/tasks/securitychecker/composeraudit.md @@ -11,6 +11,7 @@ The task lives under the `securitychecker_composeraudit` namespace and has the f grumphp: tasks: securitychecker_composeraudit: + abandoned: null format: null locked: true no_dev: false @@ -18,6 +19,12 @@ grumphp: working_dir: null ``` +**abandoned** + +*Default: null* + +You can choose the behavior on abandoned packages. The available options are `ignore`, `report` and `fail`. By default, grumphp will use the `fail` behavior. + **format** *Default: null* diff --git a/src/Task/SecurityCheckerComposeraudit.php b/src/Task/SecurityCheckerComposeraudit.php index d57dc1a6..ad324e05 100644 --- a/src/Task/SecurityCheckerComposeraudit.php +++ b/src/Task/SecurityCheckerComposeraudit.php @@ -22,6 +22,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver { $resolver = new OptionsResolver(); $resolver->setDefaults([ + 'abandoned' => null, 'format' => null, 'locked' => true, 'no_dev' => false, @@ -29,6 +30,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver 'working_dir' => null, ]); + $resolver->addAllowedTypes('abandoned', ['null', 'string']); $resolver->addAllowedTypes('format', ['null', 'string']); $resolver->addAllowedTypes('locked', ['bool']); $resolver->addAllowedTypes('no_dev', ['bool']); @@ -55,6 +57,7 @@ public function run(ContextInterface $context): TaskResultInterface $arguments = $this->processBuilder->createArgumentsForCommand('composer'); $arguments->add('audit'); + $arguments->addOptionalArgument('--abandoned=%s', $config['abandoned']); $arguments->addOptionalArgument('--format=%s', $config['format']); $arguments->addOptionalArgument('--locked', $config['locked']); $arguments->addOptionalArgument('--no-dev', $config['no_dev']); diff --git a/test/Unit/Task/SecurityCheckerComposerauditTest.php b/test/Unit/Task/SecurityCheckerComposerauditTest.php index fae103a7..8f05f2fe 100644 --- a/test/Unit/Task/SecurityCheckerComposerauditTest.php +++ b/test/Unit/Task/SecurityCheckerComposerauditTest.php @@ -25,6 +25,7 @@ public function provideConfigurableOptions(): iterable yield 'defaults' => [ [], [ + 'abandoned' => null, 'format' => null, 'locked' => true, 'no_dev' => false, @@ -148,6 +149,19 @@ public function provideExternalTaskRuns(): iterable ] ]; + yield 'abandoned' => [ + [ + 'abandoned' => 'ignore', + ], + $this->mockContext(RunContext::class, ['composer.lock']), + 'composer', + [ + 'audit', + '--abandoned=ignore', + '--locked', + ] + ]; + yield 'working-dir' => [ [ 'working_dir' => 'dir',