-
-
Notifications
You must be signed in to change notification settings - Fork 302
feat(examples): add GitLab built-in changelog templates #1561
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # git-cliff ~ configuration file | ||
| # https://git-cliff.org/docs/configuration | ||
|
|
||
| [changelog] | ||
| # A Tera template to be rendered as the changelog's header. | ||
| # See https://keats.github.io/tera/docs/#introduction | ||
| header = """ | ||
| # Changelog\n | ||
| All notable changes to this project will be documented in this file. | ||
|
|
||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n | ||
| """ | ||
| # A Tera template to be rendered for each release in the changelog. | ||
| # See https://keats.github.io/tera/docs/#introduction | ||
| body = """ | ||
| {%- macro project_url() -%} | ||
| {%- set ci_project_url = get_env(name="CI_PROJECT_URL", default="") -%} | ||
| {%- if ci_project_url != "" -%} | ||
| {{ ci_project_url }} | ||
| {%- elif remote.gitlab.api_url and remote.gitlab.owner and remote.gitlab.repo -%} | ||
| {{ remote.gitlab.api_url | trim_end_matches(pat="/api/v4") }}/{{ remote.gitlab.owner }}/{{ remote.gitlab.repo }} | ||
| {%- elif remote.gitlab.owner and remote.gitlab.repo -%} | ||
| https://gitlab.com/{{ remote.gitlab.owner }}/{{ remote.gitlab.repo }} | ||
| {%- else -%} | ||
|
|
||
| {%- endif -%} | ||
| {%- endmacro -%} | ||
|
|
||
| {% if version -%} | ||
| ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} | ||
| {% else -%} | ||
| ## [Unreleased] | ||
| {% endif -%} | ||
|
|
||
| {% for group, commits in commits | group_by(attribute="group") %} | ||
| ### {{ group | upper_first }} | ||
| {%- for commit in commits %} | ||
| - {{ commit.message | split(pat="\n") | first | upper_first | trim }}\ | ||
| {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%} | ||
| {% if commit.remote.pr_number %} in \ | ||
| [!{{ commit.remote.pr_number }}]({{ self::project_url() }}/-/merge_requests/{{ commit.remote.pr_number }}) \ | ||
| {%- endif -%} | ||
| {% endfor %} | ||
| {% endfor %} | ||
|
|
||
| {%- if gitlab.contributors | filter(attribute="is_first_time", value=true) | length != 0 %} | ||
| ### New Contributors | ||
| {%- endif -%} | ||
|
|
||
| {% for contributor in gitlab.contributors | filter(attribute="is_first_time", value=true) %} | ||
| * @{{ contributor.username }} made their first contribution | ||
| {%- if contributor.pr_number %} in \ | ||
| [!{{ contributor.pr_number }}]({{ self::project_url() }}/-/merge_requests/{{ contributor.pr_number }}) \ | ||
| {%- endif %} | ||
| {%- endfor %}\n | ||
|
|
||
| {%- if gitlab.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}{% raw %}\n{% endraw -%}{% endif %} | ||
|
|
||
| """ | ||
| # A Tera template to be rendered as the changelog's footer. | ||
| # See https://keats.github.io/tera/docs/#introduction | ||
| footer = """ | ||
| {%- macro project_url() -%} | ||
| {%- set ci_project_url = get_env(name="CI_PROJECT_URL", default="") -%} | ||
| {%- if ci_project_url != "" -%} | ||
| {{ ci_project_url }} | ||
| {%- elif remote.gitlab.api_url and remote.gitlab.owner and remote.gitlab.repo -%} | ||
| {{ remote.gitlab.api_url | trim_end_matches(pat="/api/v4") }}/{{ remote.gitlab.owner }}/{{ remote.gitlab.repo }} | ||
| {%- elif remote.gitlab.owner and remote.gitlab.repo -%} | ||
| https://gitlab.com/{{ remote.gitlab.owner }}/{{ remote.gitlab.repo }} | ||
| {%- else -%} | ||
|
|
||
| {%- endif -%} | ||
| {%- endmacro -%} | ||
|
|
||
| {% for release in releases -%} | ||
| {% if release.version -%} | ||
| {% if release.previous.version -%} | ||
| [{{ release.version | trim_start_matches(pat="v") }}]: \ | ||
| {{ self::project_url() }}/-/compare/{{ release.previous.version }}...{{ release.version }} | ||
| {% endif -%} | ||
| {% else -%} | ||
| [unreleased]: {{ self::project_url() }}/-/compare/{{ release.previous.version }}...HEAD | ||
| {% endif -%} | ||
| {% endfor %} | ||
| <!-- generated by git-cliff --> | ||
| """ | ||
| # Remove leading and trailing whitespaces from the changelog's body. | ||
| trim = true | ||
|
|
||
| [git] | ||
| # Parse commits according to the conventional commits specification. | ||
| # See https://www.conventionalcommits.org | ||
| conventional_commits = true | ||
| # Exclude commits that do not match the conventional commits specification. | ||
| filter_unconventional = false | ||
| # An array of regex based parsers to modify commit messages prior to further processing. | ||
| commit_preprocessors = [ | ||
| # Remove issue numbers. | ||
| { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }, | ||
| ] | ||
| # An array of regex based parsers for extracting data from the commit message. | ||
| # Assigns commits to groups. | ||
| # Optionally sets the commit's scope and can decide to exclude commits from further processing. | ||
| commit_parsers = [ | ||
| { message = "^[a|A]dd", group = "Added" }, | ||
| { message = "^[s|S]upport", group = "Added" }, | ||
| { message = "^[r|R]emove", group = "Removed" }, | ||
| { message = "^.*: add", group = "Added" }, | ||
| { message = "^.*: support", group = "Added" }, | ||
| { message = "^.*: remove", group = "Removed" }, | ||
| { message = "^.*: delete", group = "Removed" }, | ||
| { message = "^test", group = "Fixed" }, | ||
| { message = "^fix", group = "Fixed" }, | ||
| { message = "^.*: fix", group = "Fixed" }, | ||
| { message = "^.*", group = "Changed" }, | ||
| ] | ||
| # Exclude commits that are not matched by any commit parser. | ||
| filter_commits = false | ||
| # Order releases topologically instead of chronologically. | ||
| topo_order = false | ||
| # Order of commits in each group/release within the changelog. | ||
| # Allowed values: newest, oldest | ||
| sort_commits = "newest" |
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be some issues with formatting, can you look into it? e.g. I tried: (there is no newline before footer)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem identified and corrected. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # git-cliff ~ configuration file | ||
| # https://git-cliff.org/docs/configuration | ||
|
|
||
| # [remote.gitlab] | ||
| # owner = "orhun" | ||
| # repo = "git-cliff" | ||
| # token = "" | ||
|
|
||
| [changelog] | ||
| # A Tera template to be rendered for each release in the changelog. | ||
| # See https://keats.github.io/tera/docs/#introduction | ||
| body = """ | ||
| ## What's Changed | ||
|
|
||
| {%- if version %} in {{ version | trim_start_matches(pat="v") }}{%- endif -%} | ||
| {% for commit in commits %} | ||
| {% if commit.remote.pr_title -%} | ||
| {%- set commit_message = commit.remote.pr_title -%} | ||
| {%- else -%} | ||
| {%- set commit_message = commit.message -%} | ||
| {%- endif -%} | ||
| * {{ commit_message | split(pat="\n") | first | trim }}\ | ||
| {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%} | ||
| {% if commit.remote.pr_number %} in \ | ||
| [!{{ commit.remote.pr_number }}]({{ self::project_url() }}/-/merge_requests/{{ commit.remote.pr_number }}) \ | ||
| {%- endif %} | ||
| {%- endfor -%} | ||
|
|
||
| {%- if gitlab -%} | ||
| {% if gitlab.contributors | filter(attribute="is_first_time", value=true) | length != 0 %} | ||
| {% raw %}\n{% endraw -%} | ||
| ### New Contributors | ||
| {%- endif %}\ | ||
| {% for contributor in gitlab.contributors | filter(attribute="is_first_time", value=true) %} | ||
| * @{{ contributor.username }} made their first contribution | ||
| {%- if contributor.pr_number %} in \ | ||
| [!{{ contributor.pr_number }}]({{ self::project_url() }}/-/merge_requests/{{ contributor.pr_number }}) \ | ||
| {%- endif %} | ||
| {%- endfor -%} | ||
| {%- endif -%} | ||
|
|
||
| {% if version %} | ||
| {% if previous.version %} | ||
| **Full Changelog**: {{ self::project_url() }}/-/compare/{{ previous.version }}...{{ version }} | ||
| {% endif %} | ||
| {% else -%} | ||
| {% raw %}\n{% endraw %} | ||
| {% endif %} | ||
|
|
||
| {%- macro project_url() -%} | ||
| {%- set ci_project_url = get_env(name="CI_PROJECT_URL", default="") -%} | ||
| {%- if ci_project_url != "" -%} | ||
| {{ ci_project_url }} | ||
| {%- elif remote.gitlab.api_url and remote.gitlab.owner and remote.gitlab.repo -%} | ||
| {{ remote.gitlab.api_url | trim_end_matches(pat="/api/v4") }}/{{ remote.gitlab.owner }}/{{ remote.gitlab.repo }} | ||
| {%- elif remote.gitlab.owner and remote.gitlab.repo -%} | ||
| https://gitlab.com/{{ remote.gitlab.owner }}/{{ remote.gitlab.repo }} | ||
| {%- else -%} | ||
|
|
||
| {%- endif -%} | ||
| {%- endmacro -%} | ||
| """ | ||
| # Remove leading and trailing whitespaces from the changelog's body. | ||
| trim = true | ||
| # A Tera template to be rendered as the changelog's footer. | ||
| # See https://keats.github.io/tera/docs/#introduction | ||
| footer = """ | ||
| <!-- generated by git-cliff --> | ||
| """ | ||
| # An array of regex based postprocessors to modify the changelog. | ||
| # Replace the placeholder `<REPO>` with a URL. | ||
| postprocessors = [] | ||
|
|
||
| [git] | ||
| # Parse commits according to the conventional commits specification. | ||
| # See https://www.conventionalcommits.org | ||
| conventional_commits = false | ||
| # Exclude commits that do not match the conventional commits specification. | ||
| filter_unconventional = true | ||
| # Split commits on newlines, treating each line as an individual commit. | ||
| split_commits = false | ||
| # An array of regex based parsers to modify commit messages prior to further processing. | ||
| commit_preprocessors = [{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }] | ||
| # Exclude commits that are not matched by any commit parser. | ||
| filter_commits = false | ||
| # Order releases topologically instead of chronologically. | ||
| topo_order = false | ||
| # Order of commits in each group/release within the changelog. | ||
| # Allowed values: newest, oldest | ||
| sort_commits = "newest" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,3 +191,39 @@ The will result in: | |
| - @orhun made their first contribution in #420 | ||
| - @cliffjumper made their first contribution in #999 | ||
| ``` | ||
|
|
||
| ## GitLab Changelog | ||
|
|
||
| If you would like to create release notes tailored for GitLab, you can use the [`gitlab.toml`](https://github.com/orhun/git-cliff/tree/main/examples/gitlab.toml) example. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can mention the other template file (detailed) as well.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you very much, correction made. |
||
|
|
||
| Since it is already embedded into the binary, you can simply run: | ||
|
|
||
| ```bash | ||
| git cliff -c gitlab | ||
| ``` | ||
|
|
||
| This will generate a changelog such as: | ||
|
|
||
| ```md | ||
| ## What's Changed in v1.0.0 | ||
|
|
||
| ### Features | ||
|
|
||
| - feat(parser): add ability to parse arrays by @orhun in [!123](https://gitlab.com/orhun/git-cliff/-/merge_requests/123) | ||
|
|
||
| ### New Contributors | ||
|
|
||
| - @someone made their first contribution in [!360](https://gitlab.com/orhun/git-cliff/-/merge_requests/360) | ||
|
|
||
| **Tag**: [v1.0.0](https://gitlab.com/orhun/git-cliff/-/tags/v1.0.0) | ||
|
|
||
| <!-- generated by git-cliff --> | ||
| ``` | ||
|
|
||
| Alternatively, you can use [`gitlab-keepachangelog.toml`](https://github.com/orhun/git-cliff/tree/main/examples/gitlab-keepachangelog.toml) template which is a mix of GitLab and [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) formats. | ||
|
|
||
| Since it is already embedded into the binary, you can simply run: | ||
|
|
||
| ```bash | ||
| git cliff -c gitlab-keepachangelog | ||
| ``` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the
!prefix for the GitLab MR references? That's what we do in the other template :)e.g.
I think that should be
!1523, right?