Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser): allow whole commit context to be used in commit parsers #758

Conversation

DerTiedemann
Copy link
Contributor

@DerTiedemann DerTiedemann commented Jul 12, 2024

Description

Allow grouping of commit by arbitray context fields instead of just a limited set

Motivation and Context

Outlined in #757

How Has This Been Tested?

Tested with this config

[changelog]
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
body = """
{%- macro remote_url() -%}\
  https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}
{%- if version -%}
    ## [{{ version | trim_start_matches(pat="v") }}]({{ self::remote_url() }}/tree/{{ version | trim_start_matches(pat="v")}}) - {{ timestamp | date(format="%Y-%m-%d") }}
{%- else -%}
    ## [unreleased]
{%- endif %}
### What's changed
{% for group, commits in commits | group_by(attribute="group") %}
  #### {{ group }}
  {% for commit in commits %}
    {% if commit.github.pr_title -%}\
      {%- set commit_message = commit.github.pr_title -%}
    {%- else -%}
      {%- set commit_message = commit.message -%}
    {%- endif -%}
    * {{ commit_message | split(pat="\n") | first | trim }}\
      {% if commit.github.username %} by @{{ commit.github.username }}{%- endif -%}
      {% if commit.github.pr_number %} in \
        [#{{ commit.github.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.github.pr_number }}) \
      {%- endif %}    
  {%- endfor -%}
{% endfor %}\n
{%- if github -%}
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
  {% raw %}\n{% endraw -%}
  ### New Contributors
{%- endif %}\
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
  * @{{ contributor.username }} made their first contribution
    {%- if contributor.pr_number %} in \
      [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
    {%- endif %}
{%- endfor -%}
{%- endif -%}

{% if version %}
    {% if previous.version %}
      **Full Changelog**: {{ self::remote_url() }}/compare/{{ previous.version }}...{{ version }}
    {% endif %}
{% endif %}
"""
footer = """
<!-- generated by git-cliff -->
"""
trim = true

[git]
conventional_commits = true
filter_unconventional = false
split_commits = false
commit_parsers = [
  { message = "^Bump version", skip = true },
  { field = "github.pr_labels", pattern = "breaking-change", group = "<!-- 0 -->🏗️ Breaking changes" },
  { field = "github.pr_labels", pattern = "type/enhancement", group = "<!-- 1 -->🚀 Features" },
  { field = "github.pr_labels", pattern = "type/bug", group = "<!-- 2 -->🐛 Fixes" },
  { field = "github.pr_labels", pattern = "type/update", group = "<!-- 3 -->🧪 Dependencies" },
  { field = "github.pr_labels", pattern = "type/refactor", group = "<!-- 4 -->🏭 Refactor" },
  { field = "github.pr_labels", pattern = "area/documentation", group = "<!-- 5 -->📝 Documentation" },
  { field = "github.pr_labels", pattern = ".*", group = "<!-- 6 -->🌀 Miscellaneous" },
]
protect_breaking_commits = false
filter_commits = false
topo_order = false
sort_commits = "oldest"

on this repository.

Command ran: GITHUB_TOKEN="" git-cliff --github-repo=bakdata/kpops -o CHANGELOG.md

Screenshots / Logs (if applicable)

Excerpt from generated changelog:

Changelog

All notable changes to this project will be documented in this file.

6.1.0 - 2024-07-09

What's changed

🚀 Features

🏭 Refactor

Full Changelog: bakdata/kpops@6.0.2...6.1.0

6.0.2 - 2024-07-04

What's changed

📝 Documentation

🌀 Miscellaneous

Full Changelog: bakdata/kpops@6.0.1...6.0.2

6.0.1 - 2024-06-12

What's changed

🐛 Fixes

Full Changelog: bakdata/kpops@6.0.0...6.0.1

Types of Changes

I have reordered execution here to make sure the context object is populated when the commits are parsed.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have formatted the code with rustfmt.
  • I checked the lints with clippy.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

welcome bot commented Jul 12, 2024

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.

Project coverage is 36.83%. Comparing base (227a307) to head (134a4cd).
Report is 15 commits behind head on main.

Files Patch % Lines
git-cliff-core/src/commit.rs 70.00% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #758      +/-   ##
==========================================
+ Coverage   36.71%   36.83%   +0.12%     
==========================================
  Files          19       19              
  Lines        1501     1499       -2     
==========================================
+ Hits          551      552       +1     
+ Misses        950      947       -3     
Flag Coverage Δ
unit-tests 36.83% <72.73%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DerTiedemann DerTiedemann changed the title Allow whole commit context to be used inside of CommitParser config POC: Allow whole commit context to be used inside of CommitParser config Jul 12, 2024
@DerTiedemann DerTiedemann force-pushed the tiedemann/feat/allow-whole-context-to-be-used-in-parser-field branch from 9e39fb5 to 7db25f8 Compare July 12, 2024 12:48
@DerTiedemann DerTiedemann force-pushed the tiedemann/feat/allow-whole-context-to-be-used-in-parser-field branch from c3403f8 to 32da6d3 Compare July 30, 2024 00:20
@DerTiedemann DerTiedemann marked this pull request as ready for review July 30, 2024 00:23
@DerTiedemann DerTiedemann requested a review from orhun as a code owner July 30, 2024 00:23
Copy link
Owner

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely good to have!

Can you also update the documentation (i.e. add some examples)? Adding your use case to Tips and Tricks would be also pretty nice.

git-cliff-core/src/changelog.rs Show resolved Hide resolved
git-cliff-core/src/commit.rs Outdated Show resolved Hide resolved
git-cliff-core/src/commit.rs Show resolved Hide resolved
@orhun orhun changed the title POC: Allow whole commit context to be used inside of CommitParser config feat(parser): allow whole commit context to be used in commit parsers Jul 31, 2024
@DerTiedemann DerTiedemann requested a review from orhun August 6, 2024 01:52
Copy link
Owner

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks for the PR 🔥

@orhun orhun merged commit ccf2ab7 into orhun:main Aug 8, 2024
57 of 58 checks passed
Copy link

welcome bot commented Aug 8, 2024

Congrats on merging your first pull request! ⛰️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants