Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add composer audit abandoned behavior #1164

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/tasks/securitychecker/composeraudit.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ 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
run_always: false
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*
Expand Down
3 changes: 3 additions & 0 deletions src/Task/SecurityCheckerComposeraudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
'abandoned' => null,
'format' => null,
'locked' => true,
'no_dev' => false,
'run_always' => false,
'working_dir' => null,
]);

$resolver->addAllowedTypes('abandoned', ['null', 'string']);
$resolver->addAllowedTypes('format', ['null', 'string']);
$resolver->addAllowedTypes('locked', ['bool']);
$resolver->addAllowedTypes('no_dev', ['bool']);
Expand All @@ -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']);
Expand Down
14 changes: 14 additions & 0 deletions test/Unit/Task/SecurityCheckerComposerauditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function provideConfigurableOptions(): iterable
yield 'defaults' => [
[],
[
'abandoned' => null,
'format' => null,
'locked' => true,
'no_dev' => false,
Expand Down Expand Up @@ -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',
Expand Down
Loading