Skip to content

using --latest flag always detects new contributors (that are not new) #1096

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

Open
1 task done
mibelbahri opened this issue Mar 16, 2025 · 4 comments
Open
1 task done
Labels
bug Something isn't working integration Related to remote integration question Further information is requested

Comments

@mibelbahri
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

Hello team

I have a bug with git cliff, when using it to generate the release body, I always have new contributors popping, even if they have been contributing for a while.

Steps To Reproduce

I run this to draft the release (in a github workflow):

 git cliff \
 -vv --latest --unreleased --strip all -o CHANGES.md \
 --github-repo ${{ github.repository }} \
 --github-token ${{ secrets.GITHUB_TOKEN }} \
 --tag ${{ inputs.tag }}

Expected behavior

Expected behavior is to detect new contributors, only when there are new contributors

Screenshots / Logs

N/A

Software information

I run the latest version of git cliff in my github actions (github runner: ubuntu latest)

Additional context

The command for changelog with the same config works fine.

git cliff \
 --verbose --strip 'footer' -o CHANGELOG.md \
 --github-repo ${{ github.repository }} \
 --github-token ${{ secrets.GITHUB_TOKEN }} \
 --tag ${{ inputs.tag }}

Thank you very much for your help

@mibelbahri mibelbahri added the bug Something isn't working label Mar 16, 2025
Copy link

welcome bot commented Mar 16, 2025

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

@orhun orhun added the integration Related to remote integration label Mar 23, 2025
@orhun orhun removed their assignment Mar 23, 2025
@orhun
Copy link
Owner

orhun commented Mar 23, 2025

Hmm, interesting. My first thought about this was we were not missing all the data from GitHub thus our logic ends up putting everyone as a first contributor in the changelog.

Running this locally, I see that's not the problem and I can't reproduce. Can you share more info about the changelog you are getting?

For more context, see #363 for how the remote integration works.

I'm using the REST API for the current implementation and I'm fetching all the commits and pull requests. This sounds suboptimal but unfortunately we need all the commits to generate the required release context. For example:

git cliff -u: only generates the changelog for the unreleased changes. If we want to have a section there as "first contributors" then we need the whole commit/PR history to check if the user has contributed before. Unfortunately GitHub contributors API does not give us the SHA1 of the commits that belong to the contributors so I'm using the pull requests API.

@orhun orhun added the question Further information is requested label Mar 23, 2025
@mibelbahri
Copy link
Author

mibelbahri commented Mar 24, 2025

@orhun I don't have the issue locally, but only when I run it from github actions, here's my toml

When I run the command locally I don't have contributors detected at all, even if I'm passing the GH Token

Here are the commands I run:

For release notes:

git cliff \
  --latest --unreleased --strip all -o CHANGES.md \
  --github-repo Github_Org/Repo \
  --github-token $GH_TOKEN \
  --tag v1.0.0

For changelog:

git cliff \
  --strip 'footer' -o CHANGES.md \
  --github-repo Github_Org/Repo \
  --github-token $GH_TOKEN \
  --tag v1.0.0
# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration
#
# Lines starting with "#" are comments.
# Configuration options are organized into tables and keys.
# See documentation for more information on available options.

[remote.github]
owner = "Org-XXXX"
repo = "my-repo"

[changelog]
# template for the changelog header
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 = """
{%- macro remote_url() -%}
  https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}

{% macro print_commit(commit) -%}
    - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
        {% if commit.breaking %}[**breaking**] {% endif %}\
        {{ commit.message | upper_first }} - \
        ([{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }}))\
{% endmacro -%}

{% if version %}\
    {% if previous.version %}\
        ## [{{ version | trim_start_matches(pat="v") }}]\
          ({{ self::remote_url() }}/compare/{{ previous.version }}..{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }}
    {% else %}\
        ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
    {% endif %}\
{% else %}\
    ## [unreleased]
{% endif %}\

{% for group, commits in commits | group_by(attribute="group") %}
    ### {{ group | striptags | trim | upper_first }}
    {% for commit in commits
    | filter(attribute="scope")
    | sort(attribute="scope") %}
        {{ self::print_commit(commit=commit) }}
    {%- endfor %}
    {% for commit in commits %}
        {%- if not commit.scope -%}
            {{ self::print_commit(commit=commit) }}
        {% endif -%}
    {% endfor -%}
{% endfor -%}
{%- if github -%}
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
  ## 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 %}

"""
# template for the changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true
# postprocessors
postprocessors = [
  { pattern = '<REPO>', replace = "https://github.com/Org-XXXX/my-repo/" }, # replace repository URL
]

[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
filter_unconventional = false
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
  { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))" },
  # Check spelling of the commit with https://github.com/crate-ci/typos
  # If the spelling is incorrect, it will be automatically fixed.
  { pattern = '.*', replace_command = 'typos --write-changes -' },
]
# regex for parsing and grouping commits
commit_parsers = [
  { message = "^feat", group = "<!-- 0 -->⛰️  Features" },
  { message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
  { message = "^doc", group = "<!-- 3 -->📚 Documentation" },
  { message = "^perf", group = "<!-- 4 -->⚡ Performance" },
  { message = "^refactor\\(clippy\\)", skip = true },
  { message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
  { message = "^style", group = "<!-- 5 -->🎨 Styling" },
  { message = "^test", group = "<!-- 6 -->🧪 Testing" },
  { message = "^chore\\(release\\)", skip = true },
  { message = "^chore\\(deps.*\\)", skip = true },
  { message = "^chore\\(pr\\)", skip = true },
  { message = "^chore\\(pull\\)", skip = true },
  { message = "^chore\\(npm\\).*yarn\\.lock", skip = true },
  { message = "^chore|^ci", group = "<!-- 7 -->⚙️ Miscellaneous Tasks" },
  { body = "^grant|.*security", group = "<!-- 8 -->🛡️ Security" },
  { message = "^revert", group = "<!-- 9 -->◀️ Revert" },
  { body = ".*", group = "<!-- 10 -->◀️ Other (Unconventional) 🗂️" }
]
# 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 = true
# regex for matching git tags
tag_pattern = "v[0-9].*"
# regex for skipping tags
skip_tags = "beta|alpha"
# 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"

@roflmuffin
Copy link

I am experiencing this, but with a simpler setup of just passing the tag that is about to be created to git cliff.

For example, my git log has a commit with tag v1.0.3 and then a bunch of changes after that. If I create a new tag on the current commit with v1.0.4 those changes get accumulated properly and no new contributors are added. However if I do the same thing but instead of creating the tag, use git cliff -t v1.0.4, the same change set is generated but the contributors are listed as new.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working integration Related to remote integration question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants