From fc0aaba224f04e4c9341a7971a4302be990ee1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20de=20la=20Pen=CC=83a?= Date: Tue, 13 Oct 2026 10:22:10 +0100 Subject: [PATCH] feat: Summarise release-note tag checks Existing tags no longer each print "already imported". A run reports one summary, and a per-tag line only when a tag is imported. --- src/Console/Command/Fetch.php | 15 ++++---- src/Console/TagSyncReport.php | 55 +++++++++++++++++++++++++++++ tests/Console/TagSyncReportTest.php | 37 +++++++++++++++++++ 3 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 src/Console/TagSyncReport.php create mode 100644 tests/Console/TagSyncReportTest.php diff --git a/src/Console/Command/Fetch.php b/src/Console/Command/Fetch.php index 34762c2..eb81d79 100644 --- a/src/Console/Command/Fetch.php +++ b/src/Console/Command/Fetch.php @@ -13,6 +13,7 @@ use Nails\Console\Command\Base; use Nails\Console\Exception\ConsoleException; use Nails\Factory; +use Nails\ReleaseNotes\Console\TagSyncReport; use Nails\ReleaseNotes\Constants; use Nails\ReleaseNotes\Resource; use Nails\ReleaseNotes\Interfaces; @@ -180,6 +181,7 @@ private function syncTags(?string $sUser, ?string $sToken): self $oReleaseNotesModel = Factory::model('ReleaseNotes', Constants::MODULE_SLUG); $aExisting = $oReleaseNotesModel->getAllFlat(); + $oReport = new TagSyncReport(); $this->oOutput->writeln('Syncing tags...'); foreach ($this->aTags as $oTag) { @@ -188,13 +190,8 @@ private function syncTags(?string $sUser, ?string $sToken): self $sTag = $this->parseTagRef($oTag->ref); - $this->oOutput->write(sprintf( - ' - Processing tag %s... ', - $sTag - )); - - if (in_array($sTag, $aExisting)) { - throw new ConsoleException('already imported'); + if (!$oReport->consider($sTag, $aExisting)) { + continue; } $oResponse = $this->callGitHubApi( @@ -227,7 +224,7 @@ private function syncTags(?string $sUser, ?string $sToken): self $this->aNewTags[] = $oNewTag; - $this->oOutput->writeln('done'); + $this->oOutput->writeln($oReport->imported($sTag)); } catch (\Throwable $e) { $this->oOutput->writeln(sprintf( @@ -237,6 +234,8 @@ private function syncTags(?string $sUser, ?string $sToken): self } } + $this->oOutput->writeln($oReport->summary()); + return $this; } diff --git a/src/Console/TagSyncReport.php b/src/Console/TagSyncReport.php new file mode 100644 index 0000000..661e4d5 --- /dev/null +++ b/src/Console/TagSyncReport.php @@ -0,0 +1,55 @@ +iChecked++; + + return !in_array($sTag, $aExisting, true); + } + + public function imported(string $sTag): string + { + $this->iImported++; + + return 'Imported tag ' . $sTag; + } + + public function summary(): string + { + return sprintf('checked %d tags, imported %d', $this->iChecked, $this->iImported); + } + + /** + * @param string[] $aTags + * @param string[] $aExisting + * + * @return string[] + */ + public function lines(array $aTags, array $aExisting): array + { + $aLines = []; + + foreach ($aTags as $sTag) { + if (!$this->consider($sTag, $aExisting)) { + continue; + } + + $aLines[] = $this->imported($sTag); + } + + $aLines[] = $this->summary(); + + return $aLines; + } +} diff --git a/tests/Console/TagSyncReportTest.php b/tests/Console/TagSyncReportTest.php new file mode 100644 index 0000000..88453f5 --- /dev/null +++ b/tests/Console/TagSyncReportTest.php @@ -0,0 +1,37 @@ +lines( + ['0.9.0', '0.9.1', '1.0.0'], + ['0.9.0', '0.9.1', '1.0.0'] + ); + + self::assertSame(['checked 3 tags, imported 0'], $aLines); + self::assertStringNotContainsString('already imported', implode("\n", $aLines)); + } + + public function test_only_imported_tags_get_a_line(): void + { + $aLines = (new TagSyncReport())->lines( + ['0.9.0', '1.0.0', '1.1.0'], + ['0.9.0'] + ); + + self::assertSame( + [ + 'Imported tag 1.0.0', + 'Imported tag 1.1.0', + 'checked 3 tags, imported 2', + ], + $aLines + ); + } +}