From aa6f5c9e323c0675c5f436aefdb4b69030fa52fc Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 10 Nov 2023 11:16:03 +1300 Subject: [PATCH] FIX Ensure changelog passes linting --- src/Model/Changelog/Changelog.php | 2 +- src/Model/Changelog/ChangelogItem.php | 2 +- src/Utility/ChangelogRenderer.php | 12 ++++++++---- templates/cow/changelog/logs/by_module.md.twig | 9 +++++---- templates/cow/changelog/logs/macros.md.twig | 6 ++---- templates/cow/changelog/logs/plain.md.twig | 2 +- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Model/Changelog/Changelog.php b/src/Model/Changelog/Changelog.php index c22a684..e492a2e 100644 --- a/src/Model/Changelog/Changelog.php +++ b/src/Model/Changelog/Changelog.php @@ -264,7 +264,7 @@ protected function getMarkdownGrouped(OutputInterface $output) $groupedLog = $this->getGroupedChanges($output, $this->getLegacyChangelogCommitFilter()); // Convert to string and generate markdown (add list to beginning of each item) - $output = "\n\n## Change Log\n"; + $output = "\n\n## Change log\n"; foreach ($groupedLog as $groupName => $commits) { if (empty($commits)) { continue; diff --git a/src/Model/Changelog/ChangelogItem.php b/src/Model/Changelog/ChangelogItem.php index 60ca088..5c4abb5 100644 --- a/src/Model/Changelog/ChangelogItem.php +++ b/src/Model/Changelog/ChangelogItem.php @@ -324,7 +324,7 @@ public function getSecurityCVE() public function getMarkdown($format = null, $securityFormat = null) { if (!isset($format)) { - $format = ' * {date} [{shortHash}]({link}) {shortMessage} ({author})'; + $format = '- {date} [{shortHash}]({link}) {shortMessage} ({author})'; } $data = $this->getRenderData(); diff --git a/src/Utility/ChangelogRenderer.php b/src/Utility/ChangelogRenderer.php index 5e3f94f..440d69c 100644 --- a/src/Utility/ChangelogRenderer.php +++ b/src/Utility/ChangelogRenderer.php @@ -22,6 +22,11 @@ class ChangelogRenderer */ public const BOTTOM_DELIMITER = ''; + /** + * This prevents certain linting rules from being run against the commits + */ + public const SKIP_LINTING = ''; + /** * Renders a basic changelog, with a version title and the provided logs. * @@ -75,7 +80,7 @@ public function updateChangelog(string $existingChangelog, string $newLogs): str // If the top delimiter doesn't exist, fall back to appending the logs if ($topDelimiterPos === false) { - return $existingChangelog . self::TOP_DELIMITER . $newLogs . self::BOTTOM_DELIMITER; + return $existingChangelog . self::TOP_DELIMITER . "\n" . self::SKIP_LINTING . $newLogs . self::BOTTOM_DELIMITER; } // Extract the content preceding the logs (including the top delimiter itself) @@ -87,10 +92,9 @@ public function updateChangelog(string $existingChangelog, string $newLogs): str : substr($existingChangelog, $bottomDelimiterPos); return implode([ - $beforeLogs, + $beforeLogs . "\n" . self::SKIP_LINTING, "\n\n", $newLogs, - "\n\n", $afterLogs ]); } @@ -104,7 +108,7 @@ public function updateChangelog(string $existingChangelog, string $newLogs): str private function delimitLogs(string $logs): string { return implode("\n\n", [ - self::TOP_DELIMITER, + self::TOP_DELIMITER . "\n" . self::SKIP_LINTING, $logs, self::BOTTOM_DELIMITER ]); diff --git a/templates/cow/changelog/logs/by_module.md.twig b/templates/cow/changelog/logs/by_module.md.twig index 3850d7f..252fa9d 100644 --- a/templates/cow/changelog/logs/by_module.md.twig +++ b/templates/cow/changelog/logs/by_module.md.twig @@ -13,10 +13,11 @@ ] -%} -## Change Log +## Change log {% for section in SECTIONS %} - {%- if commits.by_type[section]|length > 0 %} - {{~ print_section(libs, commits, section, '### ' ~ section) }} - {% endif %} +{#- Don't indent these, as it will end up with indents in the final changelog which fails linting. -#} +{%- if commits.by_type[section]|length > 0 %} + {{~ print_section(libs, commits, section, '### ' ~ section) }} +{% endif %} {% endfor -%} diff --git a/templates/cow/changelog/logs/macros.md.twig b/templates/cow/changelog/logs/macros.md.twig index 2c9dc5d..66f9479 100644 --- a/templates/cow/changelog/logs/macros.md.twig +++ b/templates/cow/changelog/logs/macros.md.twig @@ -2,7 +2,7 @@ `format_commit` formats and prints a single commit (change) -#} {%- macro format_commit(commit) %} - * {{ commit.date }} [{{ commit.shortHash }}]({{ commit.link }}) {{ commit.shortMessage }} ({{ commit.author }}){% if commit.cve %} - See [{{ commit.cve }}]({{ commit.cveURL }}){% endif %} +- {{ commit.date }} [{{ commit.shortHash }}]({{ commit.link }}) {{ commit.shortMessage }} ({{ commit.author }}){% if commit.cve %} - See [{{ commit.cve }}]({{ commit.cveURL }}){% endif %} {% endmacro -%} @@ -35,14 +35,12 @@ {%- macro print_section_by_type_and_module(libraries, commits, name, title) %} {%~ if commits.by_type[name] %} {%- if title %} - {{~ title }} - {%~ endif %} {%~ for library in libraries %} {%~ if library.commits.by_type[name] %} - {{~ ' * ' ~ library.name ~ ' (' ~ library.version.prior ~ ' -> ' ~ library.version.release ~ ')' }} + {{~ '- ' ~ library.name ~ ' (' ~ library.version.prior ~ ' -> ' ~ library.version.release ~ ')' }} {%~ for commit in library.commits.by_type[name] %} {%- set commit = commit.getRenderData %} {%~ autoescape false %} diff --git a/templates/cow/changelog/logs/plain.md.twig b/templates/cow/changelog/logs/plain.md.twig index 445e2c4..6d4543e 100644 --- a/templates/cow/changelog/logs/plain.md.twig +++ b/templates/cow/changelog/logs/plain.md.twig @@ -13,7 +13,7 @@ ] -%} -## Change Log +## Change log {% for section in SECTIONS %} {%- if commits.by_type[section]|length > 0 %}