Skip to content

Commit b29b68c

Browse files
committed
fix: Add PSR default templates
It's not clever enough to only pick up custom templates, must copy their templates as a starting point for customisation.
1 parent d513369 commit b29b68c

File tree

10 files changed

+604
-0
lines changed

10 files changed

+604
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CHANGELOG
2+
3+
{% if ctx.changelog_mode == "update"
4+
%}{# # IMPORTANT: add insertion flag for next version update
5+
#}{{
6+
insertion_flag ~ "\n"
7+
8+
}}{% endif
9+
%}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{#
2+
This changelog template initializes a full changelog for the project,
3+
it follows the following logic:
4+
1. Header
5+
2. Any Unreleased Details (uncommon)
6+
3. all previous releases except the very first release
7+
4. the first release
8+
9+
#}{#
10+
# Header
11+
#}{% include "changelog_header.md.j2"
12+
-%}{#
13+
# Any Unreleased Details (uncommon)
14+
#}{% include "unreleased_changes.md.j2"
15+
-%}{#
16+
# Since this is initialization, we are generating all the previous
17+
# release notes per version. The very first release notes is specialized
18+
#}{% if releases | length > 0
19+
%}{% for release in releases
20+
%}{{ "\n"
21+
}}{% if loop.last and ctx.mask_initial_release
22+
%}{%- include "first_release.md.j2"
23+
-%}{% else
24+
%}{%- include "versioned_changes.md.j2"
25+
-%}{% endif
26+
%}{{ "\n"
27+
}}{% endfor
28+
%}{% endif
29+
%}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{#
2+
This Update changelog template uses the following logic:
3+
4+
1. Read previous changelog file (ex. project_root/CHANGELOG.md)
5+
2. Split on insertion flag (ex. <!-- version list -->)
6+
3. Print top half of previous changelog
7+
3. New Changes (unreleased commits & newly released)
8+
4. Print bottom half of previous changelog
9+
10+
Note: if a previous file was not found, it does not write anything at the bottom
11+
but render does NOT fail
12+
13+
#}{% set prev_changelog_contents = prev_changelog_file | read_file | safe
14+
%}{% set changelog_parts = prev_changelog_contents.split(insertion_flag, maxsplit=1)
15+
%}{#
16+
#}{% if changelog_parts | length < 2
17+
%}{# # insertion flag was not found, check if the file was empty or did not exist
18+
#}{% if prev_changelog_contents | length > 0
19+
%}{# # File has content but no insertion flag, therefore, file will not be updated
20+
#}{{ changelog_parts[0]
21+
}}{% else
22+
%}{# # File was empty or did not exist, therefore, it will be created from scratch
23+
#}{% include "changelog_init.md.j2"
24+
%}{% endif
25+
%}{% else
26+
%}{#
27+
# Previous Changelog Header
28+
# - Depending if there is header content, then it will separate the insertion flag
29+
# with a newline from header content, otherwise it will just print the insertion flag
30+
#}{% set prev_changelog_top = changelog_parts[0] | trim
31+
%}{% if prev_changelog_top | length > 0
32+
%}{{
33+
"%s\n\n%s\n" | format(prev_changelog_top, insertion_flag | trim)
34+
35+
}}{% else
36+
%}{{
37+
"%s\n" | format(insertion_flag | trim)
38+
39+
}}{% endif
40+
%}{#
41+
# Any Unreleased Details (uncommon)
42+
#}{% include "unreleased_changes.md.j2"
43+
-%}{#
44+
#}{% if releases | length > 0
45+
%}{# # Latest Release Details
46+
#}{% set release = releases[0]
47+
%}{#
48+
#}{% if releases | length == 1 and ctx.mask_initial_release
49+
%}{# # First Release detected
50+
#}{{ "\n"
51+
}}{%- include "first_release.md.j2"
52+
-%}{{ "\n"
53+
}}{#
54+
#}{% elif "# " ~ release.version.as_semver_tag() ~ " " not in changelog_parts[1]
55+
%}{# # The release version is not already in the changelog so we add it
56+
#}{{ "\n"
57+
}}{%- include "versioned_changes.md.j2"
58+
-%}{{ "\n"
59+
}}{#
60+
#}{% endif
61+
%}{% endif
62+
%}{#
63+
# Previous Changelog Footer
64+
# - skips printing footer if empty, which happens when the insertion_flag
65+
# was at the end of the file (ignoring whitespace)
66+
#}{% set previous_changelog_bottom = changelog_parts[1] | trim
67+
%}{% if previous_changelog_bottom | length > 0
68+
%}{{ "\n%s\n" | format(previous_changelog_bottom)
69+
}}{% endif
70+
%}{% endif
71+
%}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
{% from 'macros.md.j2' import apply_alphabetical_ordering_by_brk_descriptions
2+
%}{% from 'macros.md.j2' import apply_alphabetical_ordering_by_descriptions
3+
%}{% from 'macros.md.j2' import apply_alphabetical_ordering_by_release_notices
4+
%}{% from 'macros.md.j2' import format_breaking_changes_description, format_commit_summary_line
5+
%}{% from 'macros.md.j2' import format_release_notice
6+
%}{#
7+
EXAMPLE:
8+
9+
### Features
10+
11+
- Add new feature ([#10](https://domain.com/namespace/repo/pull/10),
12+
[`abcdef0`](https://domain.com/namespace/repo/commit/HASH))
13+
14+
- **scope**: Add new feature ([`abcdef0`](https://domain.com/namespace/repo/commit/HASH))
15+
16+
### Bug Fixes
17+
18+
- Fix bug ([#11](https://domain.com/namespace/repo/pull/11),
19+
[`abcdef1`](https://domain.com/namespace/repo/commit/HASH))
20+
21+
### Breaking Changes
22+
23+
- With the change _____, the change causes ___ effect. Ultimately, this section
24+
it is a more detailed description of the breaking change. With an optional
25+
scope prefix like the commit messages above.
26+
27+
- **scope**: this breaking change has a scope to identify the part of the code that
28+
this breaking change applies to for better context.
29+
30+
### Additional Release Information
31+
32+
- This is a release note that provides additional information about the release
33+
that is not a breaking change or a feature/bug fix.
34+
35+
- **scope**: this release note has a scope to identify the part of the code that
36+
this release note applies to for better context.
37+
38+
#}{% set max_line_width = max_line_width | default(100)
39+
%}{% set hanging_indent = hanging_indent | default(2)
40+
%}{#
41+
#}{% for type_, commits in commit_objects if type_ != "unknown"
42+
%}{# PREPROCESS COMMITS (order by description & format description line)
43+
#}{% set ns = namespace(commits=commits)
44+
%}{% set _ = apply_alphabetical_ordering_by_descriptions(ns)
45+
%}{#
46+
#}{% set commit_descriptions = []
47+
%}{#
48+
#}{% for commit in ns.commits
49+
%}{# # Update the first line with reference links and if commit description
50+
# has more than one line, add the rest of the lines
51+
# NOTE: This is specifically to make sure to not hide contents
52+
# of squash commits (until parse support is added)
53+
#}{% set description = "- %s" | format(format_commit_summary_line(commit))
54+
%}{% if commit.descriptions | length > 1
55+
%}{% set description = "%s\n\n%s" | format(
56+
description, commit.descriptions[1:] | join("\n\n")
57+
)
58+
%}{% endif
59+
%}{% set description = description | autofit_text_width(max_line_width, hanging_indent)
60+
%}{% set _ = commit_descriptions.append(description)
61+
%}{% endfor
62+
%}{#
63+
# # PRINT SECTION (header & commits)
64+
#}{% if commit_descriptions | length > 0
65+
%}{{ "\n"
66+
}}{{ "### %s\n" | format(type_ | title)
67+
}}{{ "\n"
68+
}}{{ "%s\n" | format(commit_descriptions | unique | join("\n\n"))
69+
}}{% endif
70+
%}{% endfor
71+
%}{#
72+
# Determine if there are any breaking change commits by filtering the list by breaking descriptions
73+
# commit_objects is a list of tuples [("Features", [ParsedCommit(), ...]), ("Bug Fixes", [ParsedCommit(), ...])]
74+
# HOW: Filter out breaking change commits that have no breaking descriptions
75+
# 1. Re-map the list to only the list of commits under the breaking category from the list of tuples
76+
# 2. Peel off the outer list to get a list of ParsedCommit objects
77+
# 3. Filter the list of ParsedCommits to only those with a breaking description
78+
#}{% set breaking_commits = commit_objects | map(attribute="1.0")
79+
%}{% set breaking_commits = breaking_commits | rejectattr("error", "defined") | selectattr("breaking_descriptions.0") | list
80+
%}{#
81+
#}{% if breaking_commits | length > 0
82+
%}{# PREPROCESS COMMITS
83+
#}{% set brk_ns = namespace(commits=breaking_commits)
84+
%}{% set _ = apply_alphabetical_ordering_by_brk_descriptions(brk_ns)
85+
%}{#
86+
#}{% set brking_descriptions = []
87+
%}{#
88+
#}{% for commit in brk_ns.commits
89+
%}{% set full_description = "- %s" | format(
90+
format_breaking_changes_description(commit).split("\n\n") | join("\n\n- ")
91+
)
92+
%}{% set _ = brking_descriptions.append(
93+
full_description | autofit_text_width(max_line_width, hanging_indent)
94+
)
95+
%}{% endfor
96+
%}{#
97+
# # PRINT BREAKING CHANGE DESCRIPTIONS (header & descriptions)
98+
#}{{ "\n"
99+
}}{{ "### Breaking Changes\n"
100+
}}{{
101+
"\n%s\n" | format(brking_descriptions | unique | join("\n\n"))
102+
}}{#
103+
#}{% endif
104+
%}{#
105+
# Determine if there are any commits with release notice information by filtering the list by release_notices
106+
# commit_objects is a list of tuples [("Features", [ParsedCommit(), ...]), ("Bug Fixes", [ParsedCommit(), ...])]
107+
# HOW: Filter out commits that have no release notices
108+
# 1. Re-map the list to only the list of commits from the list of tuples
109+
# 2. Peel off the outer list to get a list of ParsedCommit objects
110+
# 3. Filter the list of ParsedCommits to only those with a release notice
111+
#}{% set notice_commits = commit_objects | map(attribute="1.0")
112+
%}{% set notice_commits = notice_commits | rejectattr("error", "defined") | selectattr("release_notices.0") | list
113+
%}{#
114+
#}{% if notice_commits | length > 0
115+
%}{# PREPROCESS COMMITS
116+
#}{% set notice_ns = namespace(commits=notice_commits)
117+
%}{% set _ = apply_alphabetical_ordering_by_release_notices(notice_ns)
118+
%}{#
119+
#}{% set release_notices = []
120+
%}{#
121+
#}{% for commit in notice_ns.commits
122+
%}{% set full_description = "- %s" | format(
123+
format_release_notice(commit).split("\n\n") | join("\n\n- ")
124+
)
125+
%}{% set _ = release_notices.append(
126+
full_description | autofit_text_width(max_line_width, hanging_indent)
127+
)
128+
%}{% endfor
129+
%}{#
130+
# # PRINT RELEASE NOTICE INFORMATION (header & descriptions)
131+
#}{{ "\n"
132+
}}{{ "### Additional Release Information\n"
133+
}}{{
134+
"\n%s\n" | format(release_notices | unique | join("\n\n"))
135+
}}{#
136+
#}{% endif
137+
%}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{# EXAMPLE:
2+
3+
## vX.X.X (YYYY-MMM-DD)
4+
5+
_This release is published under the MIT License._ # Release Notes Only
6+
7+
- Initial Release
8+
9+
#}{{
10+
"## %s (%s)\n" | format(
11+
release.version.as_semver_tag(),
12+
release.tagged_date.strftime("%Y-%m-%d")
13+
)
14+
}}{% if license_name is defined and license_name
15+
%}{{ "\n_This release is published under the %s License._\n" | format(license_name)
16+
}}{% endif
17+
%}
18+
- Initial Release

0 commit comments

Comments
 (0)