Skip to content

Commit fe6a7e7

Browse files
authored
feat(changelog): add changelog_table component (python-semantic-release#242)
Add an alternative changelog component which displays each section as a row in a table. Fixes python-semantic-release#237
1 parent 56280df commit fe6a7e7

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

docs/configuration.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ The following components are included in Python Semantic Release:
204204
List of commits between this version and the previous one, with sections and
205205
headings for each type of change present in the release.
206206

207+
- :py:func:`semantic_release.changelog.changelog_table`
208+
209+
List of commits between this version and the previous one, dsplayed in a
210+
table.
211+
207212
- :py:func:`semantic_release.changelog.compare_url`
208213

209214
Link to view a comparison between this release and the previous one on

semantic_release/changelog/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from ..helpers import LoggedFunction
44
from ..settings import config, current_changelog_components
55

6-
from .changelog import changelog_headers # noqa isort:skip
6+
from .changelog import changelog_headers, changelog_table # noqa isort:skip
77
from .compare import compare_url # noqa isort:skip
88

99
logger = logging.getLogger(__name__)

semantic_release/changelog/changelog.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,17 @@ def changelog_headers(
2828
output += "* {0} ({1})\n".format(item[1], item[0])
2929

3030
return output
31+
32+
33+
def changelog_table(
34+
changelog: dict, changelog_sections: list, **kwargs
35+
) -> str:
36+
output = "| Type | Change |\n| --- | --- |\n"
37+
38+
for section in get_changelog_sections(changelog, changelog_sections):
39+
items = "<br>".join([
40+
f"{item[0]} ({item[1]})" for item in changelog[section]
41+
])
42+
output += f"| {section.title()} | {items} |\n"
43+
44+
return output

tests/test_changelog.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import mock
22

33
from semantic_release.changelog import markdown_changelog
4-
from semantic_release.changelog.changelog import get_changelog_sections
4+
from semantic_release.changelog.changelog import get_changelog_sections, changelog_table
55
from semantic_release.changelog.compare import compare_url, get_github_compare_url
66

77

@@ -38,6 +38,18 @@ def test_markdown_changelog():
3838
)
3939

4040

41+
def test_changelog_table():
42+
assert changelog_table({
43+
"feature": [("commit1", "sha1"), ("commit2", "sha2")],
44+
"fix": [("commit3", "sha3")]
45+
}, ["section1", "section2"]) == (
46+
"| Type | Change |\n"
47+
"| --- | --- |\n"
48+
"| Feature | commit1 (sha1)<br>commit2 (sha2) |\n"
49+
"| Fix | commit3 (sha3) |\n"
50+
)
51+
52+
4153
def test_should_not_output_heading():
4254
assert "v1.0.1" not in markdown_changelog("1.0.1", {},)
4355

0 commit comments

Comments
 (0)