Skip to content

Commit

Permalink
feat(cli): generate changelog from JSON context (#784)
Browse files Browse the repository at this point in the history
* feat(cli): generate changelog from JSON context

* Add 'extra' field to releases and commits

* Add fixture test

* Serialize extra field for commits

* Format

* Adjust test expectations

* Add missing fields in tests

* Add usage page

* refactor(arg): update from-context argument details

* refactor(from-context): polish implementation

* docs(from-context): extend documentation

* fix(from-context): revert stdin handling

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
  • Loading branch information
janbuchar and orhun authored Aug 23, 2024
1 parent 1956c83 commit 3b6156d
Show file tree
Hide file tree
Showing 14 changed files with 840 additions and 48 deletions.
34 changes: 34 additions & 0 deletions .github/fixtures/test-from-context/cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[changelog]
# template for the changelog footer
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}{% if extra.note %} - {{ extra.note }}{% endif %}
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {{ commit.message | upper_first }}{% if commit.extra.note %} ({{ commit.extra.note }}){% endif %}\
{% endfor %}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true

[git]
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^feat", group = "Features", default_scope = "app" },
{ message = "^fix", group = "Bug Fixes", scope = "cli" },
]
11 changes: 11 additions & 0 deletions .github/fixtures/test-from-context/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e

GIT_COMMITTER_DATE="2022-04-06 01:25:08" git commit --allow-empty -m "Initial commit"
GIT_COMMITTER_DATE="2022-04-06 01:25:09" git commit --allow-empty -m "feat: add feature 1"
GIT_COMMITTER_DATE="2022-04-06 01:25:10" git commit --allow-empty -m "fix: fix feature 1"
git tag v0.1.0
GIT_COMMITTER_DATE="2022-04-06 01:25:11" git commit --allow-empty -m "feat(gui): add feature 2"
GIT_COMMITTER_DATE="2022-04-06 01:25:12" git commit --allow-empty -m "fix(gui): fix feature 2 SHOULD NOT BE IN THE CHANGELOG"
git tag v0.2.0
GIT_COMMITTER_DATE="2022-04-06 01:25:13" git commit --allow-empty -m "test: add tests"
Loading

0 comments on commit 3b6156d

Please sign in to comment.