Skip to content

Commit

Permalink
FIX Ensure changelog passes linting
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 10, 2023
1 parent 589aee8 commit 9185510
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Model/Changelog/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Changelog/ChangelogItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 8 additions & 4 deletions src/Utility/ChangelogRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class ChangelogRenderer
*/
public const BOTTOM_DELIMITER = '<!--- Changes above this line will be automatically regenerated -->';

/**
* This prevents certain linting rules from being run against the commits
*/
public const SKIP_LINTING = '<!-- markdownlint-disable proper-names enhanced-proper-names -->';

/**
* Renders a basic changelog, with a version title and the provided logs.
*
Expand Down Expand Up @@ -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)
Expand All @@ -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
]);
}
Expand All @@ -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
]);
Expand Down
9 changes: 5 additions & 4 deletions templates/cow/changelog/logs/by_module.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}
{% endif %}
{% endfor -%}
17 changes: 10 additions & 7 deletions templates/cow/changelog/logs/macros.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
`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 -%}

{#-
`anchor_for_type` generates an anchor for a changelog heading.
Must be on one line to avoid creating new lines which fail linting.
-#}
{%- macro anchor_for_type(type) %}{{' {#changelog-' ~ type|lower|replace({' ': '-'}) ~ '}' }}{% endmacro -%}

{#-
`print_section_by_type` formats and prints a single section (commit type, e.g. Bugfixes)
Expand Down Expand Up @@ -32,17 +37,15 @@
`print_section_by_type_and_module` formats and prints a single section (commit type, e.g. Bugfixes),
splitting the commits by module within the section.
-#}
{%- macro print_section_by_type_and_module(libraries, commits, name, title) %}
{%- macro print_section_by_type_and_module(libraries, commits, name) %}
{%~ if commits.by_type[name] %}
{%- if title %}

{{~ title }}

{%- if name %}
{{~ '### ' ~ name|capitalize ~ _self.anchor_for_type(name) }}
{%~ 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 %}
Expand Down
2 changes: 1 addition & 1 deletion templates/cow/changelog/logs/plain.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
]
-%}

## Change Log
## Change log

{% for section in SECTIONS %}
{%- if commits.by_type[section]|length > 0 %}
Expand Down

0 comments on commit 9185510

Please sign in to comment.