Skip to content

Commit 224422c

Browse files
committed
📝 Distinguish issues/PRs/commits/refs @ changelog
1 parent 4eb7dfa commit 224422c

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

CHANGES/.TEMPLATE.rst

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,59 @@
1414
{{ underline * definitions[category]['name']|length }}
1515

1616
{% if definitions[category]['showcontent'] %}
17-
{% for text, pr_issue_numbers in sections[section][category].items() %}
18-
- {{ text + '\n' }}
17+
{% for text, change_note_refs in sections[section][category].items() %}
18+
- {{ text }}
1919

20+
{{- '\n' * 2 -}}
21+
22+
{#-
23+
NOTE: Replacing 'e' with 'f' is a hack that prevents Jinja's `int`
24+
NOTE: filter internal implementation from treating the input as an
25+
NOTE: infinite float when it looks like a scientific notation (with a
26+
NOTE: single 'e' char in between digits), raising an `OverflowError`,
27+
NOTE: subsequently. 'f' is still a hex letter so it won't affect the
28+
NOTE: check for whether it's a (short or long) commit hash or not.
29+
Ref: https://github.com/pallets/jinja/issues/1921
30+
-#}
31+
{%-
32+
set pr_issue_numbers = change_note_refs
33+
| map('lower')
34+
| map('replace', 'e', 'f')
35+
| map('int', default=None)
36+
| select('integer')
37+
| map('string')
38+
| list
39+
-%}
40+
{%- set arbitrary_refs = [] -%}
41+
{%- set commit_refs = [] -%}
42+
{%- with -%}
43+
{%- set commit_ref_candidates = change_note_refs | reject('in', pr_issue_numbers) -%}
44+
{%- for cf in commit_ref_candidates -%}
45+
{%- if cf | length in (7, 8, 40) and cf | int(default=None, base=16) is not none -%}
46+
{%- set _ = commit_refs.append(cf) -%}
47+
{%- else -%}
48+
{%- set _ = arbitrary_refs.append(cf) -%}
49+
{%- endif -%}
50+
{%- endfor -%}
51+
{%- endwith -%}
52+
53+
{% if pr_issue_numbers %}
2054
*Related issues and pull requests on GitHub:*
21-
{{ pr_issue_numbers | join(', ') }}.
55+
:issue:`{{ pr_issue_numbers | join('`, :issue:`') }}`.
56+
{{- '\n' * 2 -}}
57+
{%- endif -%}
58+
59+
{% if commit_refs %}
60+
*Related commits on GitHub:*
61+
:commit:`{{ commit_refs | join('`, :commit:`') }}`.
62+
{{- '\n' * 2 -}}
63+
{%- endif -%}
64+
65+
{% if arbitrary_refs %}
66+
*Unlinked references:*
67+
{{ arbitrary_refs | join(', ') }}.
68+
{{- '\n' * 2 -}}
69+
{%- endif -%}
2270

2371
{% endfor %}
2472
{% else %}

towncrier.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
directory = "CHANGES/"
55
title_format = "v{version}"
66
template = "CHANGES/.TEMPLATE.rst"
7-
issue_format = ":issue:`{issue}`"
7+
issue_format = "{issue}"
88

99
# NOTE: The types are declared because:
1010
# NOTE: - there is no mechanism to override just the value of

0 commit comments

Comments
 (0)