File: macros.common.j2

package info (click to toggle)
python-semantic-release 10.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,112 kB
  • sloc: python: 36,523; sh: 340; makefile: 156
file content (160 lines) | stat: -rw-r--r-- 5,340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{# TODO: move to configuration for user to modify #}
{% set section_heading_translations = {
    'feat': 'features',
    'fix': 'bug fixes',
    'perf': 'performance improvements',
    'docs': 'documentation',
    'build': 'build system',
    'refactor': 'refactoring',
    'test': 'testing',
    'ci': 'continuous integration',
    'chore': 'chores',
    'style': 'code style',
  }
%}

{% set section_heading_order = section_heading_translations.values() %}

{% set emoji_map = {
    'breaking': '๐Ÿ’ฅ',
    'features': 'โœจ',
    'bug fixes': '๐Ÿชฒ',
    'performance improvements': 'โšก',
    'documentation': '๐Ÿ“–',
    'build system': 'โš™๏ธ',
    'refactoring': 'โ™ป๏ธ',
    'testing': 'โœ…',
    'continuous integration': '๐Ÿค–',
    'chores': '๐Ÿงน',
    'code style': '๐ŸŽจ',
    'unknown': 'โ—',
    'release_note': '๐Ÿ’ก',
} %}


{#
  MACRO: Capitalize the first letter of a string only
#}{%  macro capitalize_first_letter_only(sentence)
%}{{    (sentence[0] | upper) ~ sentence[1:]
}}{%  endmacro
%}


{#
  MACRO: format a commit descriptions list by:
  - Capitalizing the first line of the description
  - Adding an optional scope prefix
  - Joining the rest of the descriptions with a double newline
#}{%  macro format_attr_paragraphs(commit, attribute)
%}{#    NOTE: requires namespace because of the way Jinja2 handles variable scoping with loops
#}{%    set ns = namespace(full_description="")
%}{#
#}{%    if commit.error is undefined
%}{%      for paragraph in commit | attr(attribute)
%}{%        if paragraph | trim | length > 0
%}{#
#}{%          set ns.full_description = [
                ns.full_description,
                capitalize_first_letter_only(paragraph) | trim | safe,
              ] | join("\n\n")
%}{#
#}{%        endif
%}{%      endfor
%}{#
#}{%      set ns.full_description = ns.full_description | trim
%}{#
#}{%      if commit.scope
%}{%        set ns.full_description = "**%s**: %s" | format(
              commit.scope, ns.full_description
            )
%}{%      endif
%}{%    endif
%}{#
#}{{    ns.full_description
}}{%  endmacro
%}


{#
  MACRO: format the breaking changes description by:
  - Capitalizing the description
  - Adding an optional scope prefix
#}{%  macro format_breaking_changes_description(commit)
%}{{    format_attr_paragraphs(commit, 'breaking_descriptions')
}}{%  endmacro
%}


{#
  MACRO: format the release notice by:
  - Capitalizing the description
  - Adding an optional scope prefix
#}{%  macro format_release_notice(commit)
%}{{    format_attr_paragraphs(commit, "release_notices")
}}{%  endmacro
%}


{#
   MACRO: order commits alphabetically by scope and attribute
   - Commits are sorted based on scope and then the attribute alphabetically
   - Commits without scope are placed first and sorted alphabetically by the attribute
   - parameter: ns (namespace) object with a commits list
   - parameter: attr (string) attribute to sort by
   - returns None but modifies the ns.commits list in place
#}{%  macro order_commits_alphabetically_by_scope_and_attr(ns, attr)
%}{%    set ordered_commits = []
%}{#
   #    # Eliminate any ParseError commits from input set
#}{%    set filtered_commits = ns.commits | rejectattr("error", "defined") | list
%}{#
   #    # grab all commits with no scope and sort alphabetically by attr
#}{%    for commit in filtered_commits | rejectattr("scope") | sort(attribute=attr)
%}{%      set _ = ordered_commits.append(commit)
%}{%     endfor
%}{#
   #    # grab all commits with a scope and sort alphabetically by the scope and then attr
#}{%    for commit in filtered_commits | selectattr("scope") | sort(attribute=(['scope', attr] | join(",")))
%}{%      set _ = ordered_commits.append(commit)
%}{%    endfor
%}{#
   #    # Return the ordered commits
#}{%    set ns.commits = ordered_commits
%}{%  endmacro
%}


{#
  MACRO: apply smart ordering of commits objects based on alphabetized summaries and then scopes
  - Commits are sorted based on the commit type and the commit message
  - Commits are grouped by the commit type
  - parameter: ns (namespace) object with a commits list
  - returns None but modifies the ns.commits list in place
#}{%  macro apply_alphabetical_ordering_by_descriptions(ns)
%}{%    set _ = order_commits_alphabetically_by_scope_and_attr(ns, 'descriptions.0')
%}{%  endmacro
%}


{#
  MACRO: apply smart ordering of commits objects based on alphabetized breaking changes and then scopes
  - Commits are sorted based on the commit type and the commit message
  - Commits are grouped by the commit type
  - parameter: ns (namespace) object with a commits list
  - returns None but modifies the ns.commits list in place
#}{%  macro apply_alphabetical_ordering_by_brk_descriptions(ns)
%}{%    set _ = order_commits_alphabetically_by_scope_and_attr(ns, 'breaking_descriptions.0')
%}{%  endmacro
%}


{#
  MACRO: apply smart ordering of commits objects based on alphabetized release notices and then scopes
  - Commits are sorted based on the commit type and the commit message
  - Commits are grouped by the commit type
  - parameter: ns (namespace) object with a commits list
  - returns None but modifies the ns.commits list in place
#}{%  macro apply_alphabetical_ordering_by_release_notices(ns)
%}{%    set _ = order_commits_alphabetically_by_scope_and_attr(ns, 'release_notices.0')
%}{%  endmacro
%}