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

GitLab does not have merge request number for new contributors #810

Open
joergklein opened this issue Aug 23, 2024 · 2 comments
Open

GitLab does not have merge request number for new contributors #810

joergklein opened this issue Aug 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@joergklein
Copy link

Please take a look at cliff.toml and GitLab (Discussion #730)

new contributors Needs the merge_number after the !
There seems to be a bug with this, I'm not sure what is going on. Feel free to create a separate issue and I can look into it.

In the meantime you can add a guard like this:

{% for contributor in contributors %}
  {% if contributor.pr_number -%}\
    * [@{{ contributor.username }}](https://gitlab.com/{{ contributor.username }}) made their first contribution in [!{{ contributor.pr_number }}](<REPO>/-/merge_requests/{{ contributor.pr_number }})\
  {% endif -%}\
{%- endfor %}\n

Is it possible to put this lines into the code below? The error message witch I get is:

 git-cliff -r . > CHANGELOG.md
 WARN  git_cliff_core::changelog > You are using an experimental feature! Please report bugs at <https://git-cliff.org/issues>
 ERROR git_cliff                 > Template render error:
Variable `contributors` not found in context while rendering 'template'
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

cliff.toml

# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration

[remote.gitlab]
owner = "user"
repo = "test"
token = ""

[changelog]
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
header = """
# Changelog\n
This is an automated changelog based on the commits in this repository.\n

### Releases

Check the notes in the [releases](https://gitlab.com/user/test/-/releases) for more information.
"""
# https://keats.github.io/tera/docs/#introduction
body = """
{% 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 %}
        - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first | trim }} ([{{ commit.id | truncate(length=7, end="") }}](<REPO>/commit/{{ commit.id }}))\
            {% if commit.gitlab.username and commit.gitlab.username != remote.gitlab.owner %} by [@{{ commit.gitlab.username }}](https://gitlab.com/{{ commit.gitlab.username }}){%- endif -%}
            {% if commit.gitlab.pr_number %} in [#{{ commit.gitlab.pr_number }}]( <REPO>/-/commit/{{ commit.gitlab.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 }}](https://gitlab.com/{{ contributor.username }}) made their first contribution in [!{{ contributor.pr_number }}](<REPO>/-/merge_requests/{{ contributor.pr_number }})\
{%- endfor %}\n
"""
# changelog footer
footer = """
{% for release in releases -%}
    {% if release.version -%}
        {% if release.previous.version -%}
            [{{ release.version | trim_start_matches(pat="v") }}]: \
                <REPO>/-/compare/{{ release.previous.version }}...{{ release.version }}
        {% endif -%}
    {% else -%}
        [unreleased]: <REPO>/-/compare/{{ release.previous.version }}...HEAD
    {% endif -%}
{% endfor %}
"""
# remove the leading and trailing whitespace from the template
trim = true
postprocessors = [
  { pattern = '<REPO>', replace = "https://gitlab.com/joklein/test" }, # replace repository URL
]

[git]
# https://www.conventionalcommits.org
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
filter_unconventional = true
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
  # Replace issue numbers
  { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))" },
  { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/merge_requests/${2}))" },
  { pattern = '\(!([0-9]+)\)', replace = "([!${1}](<REPO>/-/merge_requests/${1}))" },
]
commit_parsers = [
  { message = "^feat", group = "Features" },
  { message = "^fix", group = "Bug Fixes" },
  { message = "^doc", group = "Documentation" },
  { message = "^perf", group = "Performance" },
  { message = "^refactor", group = "Refactor" },
  { message = "^style", group = "Styling" },
  { message = "^test", group = "Testing" },
  { message = "^chore\\(release\\): prepare for", skip = true },
  { message = "^chore\\(deps\\)", skip = true },
  { message = "^chore\\(pr\\)", skip = true },
  { message = "^chore\\(commit\\)", skip = true },
  { message = "^chore|ci", group = "Miscellaneous Tasks" },
  { body = ".*security", group = "Security" },
  { message = "^revert", group = "Revert" },
]
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers
filter_commits = false
# regex for matching git tags
# tag_pattern = "v[0-9].*"
# regex for skipping tags
# skip_tags = ""
# regex for ignoring tags
# ignore_tags = ""
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "newest"
# limit the number of commits included in the changelog.
# limit_commits = 42
Copy link

welcome bot commented Aug 23, 2024

Thanks for opening your first issue at git-cliff! Be sure to follow the issue template! ⛰️

@orhun orhun added the bug Something isn't working label Aug 23, 2024
@orhun orhun changed the title New contributors needs the merge_number after the ! GitLab does not have merge request number for new contributors Aug 23, 2024
@orhun
Copy link
Owner

orhun commented Aug 23, 2024

You can update the body like so:

body = """
{% 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 %}
        - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first | trim }} ([{{ commit.id | truncate(length=7, end="") }}](<REPO>/commit/{{ commit.id }}))\
            {% if commit.gitlab.username and commit.gitlab.username != remote.gitlab.owner %} by [@{{ commit.gitlab.username }}](https://gitlab.com/{{ commit.gitlab.username }}){%- endif -%}
            {% if commit.gitlab.pr_number %} in [#{{ commit.gitlab.pr_number }}]( <REPO>/-/commit/{{ commit.gitlab.pr_number }}){%- endif -%}
    {% endfor %}
{% endfor %}

{%- if gitlab.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
  ## New Contributors
{%- endif -%}

{% for contributor in contributors %}
  {% if contributor.pr_number -%}\
    * [@{{ contributor.username }}](https://gitlab.com/{{ contributor.username }}) made their first contribution in [!{{ contributor.pr_number }}](<REPO>/-/merge_requests/{{ contributor.pr_number }})\
  {% endif -%}\
{%- endfor %}\n
"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants