1
0
Fork 0

Fix audit command to exit with amount of advisories matched

pull/10896/head
Jordi Boggiano 2022-06-23 12:31:09 +02:00
parent e3c46cb2b2
commit 658f56ff13
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 7 additions and 3 deletions

View File

@ -47,7 +47,8 @@ EOT
} }
$auditor = new Auditor($httpDownloader); $auditor = new Auditor($httpDownloader);
return $auditor->audit($this->getIO(), $packages, $this->getAuditFormat($input, 'format'), false);
return min(255, $auditor->audit($this->getIO(), $packages, $this->getAuditFormat($input, 'format'), false));
} }
/** /**

View File

@ -43,7 +43,7 @@ class Auditor
* @param PackageInterface[] $packages * @param PackageInterface[] $packages
* @param self::FORMAT_* $format The format that will be used to output audit results. * @param self::FORMAT_* $format The format that will be used to output audit results.
* @param bool $warningOnly If true, outputs a warning. If false, outputs an error. * @param bool $warningOnly If true, outputs a warning. If false, outputs an error.
* @return int * @return int Amount of advisories found
* @throws InvalidArgumentException If no packages are passed in * @throws InvalidArgumentException If no packages are passed in
*/ */
public function audit(IOInterface $io, array $packages, string $format, bool $warningOnly = true): int public function audit(IOInterface $io, array $packages, string $format, bool $warningOnly = true): int
@ -56,9 +56,12 @@ class Auditor
$punctuation = $format === 'summary' ? '.' : ':'; $punctuation = $format === 'summary' ? '.' : ':';
$io->writeError("<$errorOrWarn>Found $numAdvisories security vulnerability advisor{$plurality}{$punctuation}</$errorOrWarn>"); $io->writeError("<$errorOrWarn>Found $numAdvisories security vulnerability advisor{$plurality}{$punctuation}</$errorOrWarn>");
$this->outputAdvisories($io, $advisories, $format); $this->outputAdvisories($io, $advisories, $format);
return 1;
return count($advisories);
} }
$io->writeError('<info>No security vulnerability advisories found</info>'); $io->writeError('<info>No security vulnerability advisories found</info>');
return 0; return 0;
} }