Skip to content

Commit

Permalink
Better messages when there aren't updates / fixed securities
Browse files Browse the repository at this point in the history
  • Loading branch information
omarlopesino committed Mar 2, 2023
1 parent 144bfc1 commit 0a5946c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
13 changes: 11 additions & 2 deletions src/ComposerDiffPeriodCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,17 @@ public function execute(InputInterface $input, OutputInterface $output) : int {
$output->writeln("\n");
$composer_lock_diff = json_decode($this->runCommand(sprintf('composer-lock-diff --from %s --to %s --json', $composer_lock_from_filepath, $composer_lock_to_filename))->getOutput(), true);

$this->printComposerChanges($composer_lock_diff['changes'], 'Production changes', $output);
$this->printComposerChanges($composer_lock_diff['changes-dev'], 'Development changes', $output);
if (!empty($composer_lock_diff['changes'])) {
$this->printComposerChanges($composer_lock_diff['changes'], 'Production changes', $output);
}

if (!empty($composer_lock_diff['changes-dev'])) {
$this->printComposerChanges($composer_lock_diff['changes-dev'], 'Development changes', $output);
}

if (empty($composer_lock_diff['changes']) && empty($composer_lock_diff['changes-dev'])) {
$output->writeln('No changes has been found in the selected period.');
}

$this->cleanup();

Expand Down
51 changes: 28 additions & 23 deletions src/SecuritiesFixedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,31 @@ public function execute(InputInterface $input, OutputInterface $output) : int {
$this->saveComposerCommitStatus($this->getFirstCommit($from, $branch), $this->getComposerJsonFromLocation());
$this->saveComposerCommitStatus($this->getLastCommit($to, $branch), $this->getComposerJsonToLocation());

$output->writeln("\n");
$fixed_advisories_table = $this->getComposerFixedSecurityAdvisories($to, $output);
$output->writeln('Fixed security advisories (Composer):');
$fixed_advisories_table->render();
$fixed_advisories = $this->getComposerFixedSecurityAdvisories($to, $output);
if (!empty($fixed_advisories)) {
$output->writeln("\n");
$fixed_advisories_table = new Table($output);
$fixed_advisories_table->setHeaders(['Package', 'CVE', 'Link']);
$fixed_advisories_table->setRows($fixed_advisories);
$output->writeln('Fixed security advisories (Composer):');
$fixed_advisories_table->render();
}

$fixed_drupal_securities = $this->getFixedDrupalSecurities($output);

if (!empty($fixed_drupal_securities)) {
$output->writeln("\n");
$fixed_drupal_advisories_table = new Table($output);
$fixed_drupal_advisories_table->setHeaders(['Package', 'From', 'To']);
$fixed_drupal_advisories_table->setRows($fixed_drupal_securities);

$output->writeln("\n");
$fixed_drupal_advisories_table = $this->getFixedDrupalSecurities($output);
$output->writeln('Fixed security advisories (Drupal):');
$fixed_drupal_advisories_table->render();
$output->writeln('Fixed security advisories (Drupal):');
$fixed_drupal_advisories_table->render();
}

if (empty($fixed_advisories) && empty($fixed_drupal_securities)) {
$output->writeln("\nThere aren't fixed security advisories at this period.");
}

$this->cleanup();
return 0;
Expand All @@ -71,14 +87,9 @@ protected function getComposerFixedSecurityAdvisories(string $to, OutputInterfac
$from_advisories = $this->getFolderSecurityAdvisoriesByDate($this->getComposerJsonFromLocation(), $to);
$to_advisories = $this->getFolderSecurityAdvisoriesByDate($this->getComposerJsonToLocation(), $to);

$fixed_advisories = array_values(array_filter($from_advisories, function ($advisory_key) use($to_advisories) {
return array_values(array_filter($from_advisories, function ($advisory_key) use($to_advisories) {
return !array_key_exists($advisory_key, $to_advisories);
}, ARRAY_FILTER_USE_KEY));

$table = new Table($output);
$table->setHeaders(['Package', 'CVE', 'Link']);
$table->setRows($fixed_advisories);
return $table;
}

/**
Expand All @@ -92,8 +103,8 @@ protected function getComposerFixedSecurityAdvisories(string $to, OutputInterfac
* @param OutputInterface $output
* Output to create the table with results.
*
* @return Table
* Table ready to render the securities.
* @return array
* List of securities.
*/
protected function getFixedDrupalSecurities(OutputInterface $output) {
$from_advisories = $this->getFolderDrupalAdvisories($this->getComposerJsonFromLocation());
Expand All @@ -104,7 +115,7 @@ protected function getFixedDrupalSecurities(OutputInterface $output) {
}, ARRAY_FILTER_USE_KEY));

$composer_lock_to_data = $this->getComposerLockData($this->getComposerJsonToLocation());
$fixed_securities = array_filter(array_map(function ($advisory) use ($composer_lock_to_data) {
return array_filter(array_map(function ($advisory) use ($composer_lock_to_data) {
$data = [
'name' => $advisory['name'],
'from' => $advisory['version'],
Expand All @@ -118,12 +129,6 @@ protected function getFixedDrupalSecurities(OutputInterface $output) {
}
return $data;
}, $fixed_securities));

$table = new Table($output);
$table->setHeaders(['Package', 'From', 'To']);
$table->setRows($fixed_securities);

return $table;
}

/**
Expand Down

0 comments on commit 0a5946c

Please sign in to comment.