Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Ensure changelog passes linting #249

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 13 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,12 @@ 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 +97,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 +113,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
2 changes: 1 addition & 1 deletion tests/Model/ChangelogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testGetMarkdownGroupedContainsHeadings()
{
$result = $this->changelog->getMarkdown($this->output, Changelog::FORMAT_GROUPED);

$this->assertStringContainsString('## Change Log', $result);
$this->assertStringContainsString('## Change log', $result);
$this->assertStringContainsString('### Security', $result);
$this->assertStringContainsString('### Bugfixes', $result);
$this->assertStringContainsString('### Features and Enhancements', $result);
Expand Down