marcocesarato / php-conventional-changelog

A PHP tool built to generate a changelog from a project's commit messages and metadata following the conventionalcommits.org and automate versioning with semver.org.
GNU General Public License v3.0
227 stars 32 forks source link

New getLastTag logic doesn't find my beta tags #48

Closed adambalint-srg closed 1 year ago

adambalint-srg commented 1 year ago

The new logic which was implemented in #47 by @marcocesarato doesn't find previous beta tags. In my repository I have only alpha and beta versions now, like v2.0.0-beta.8. I don't have v2.0.0 now, because the code is not in this phase yet. But the preg_grep fiters out every tag which contains - https://github.com/marcocesarato/php-conventional-changelog/blob/92e3adbe75259f9a88047865324ae8e00cef7c66/src/Git/Repository.php#L74

Why this logic was implemented? I can't create v2.0.0-beta.9 version because of this logic.

marcocesarato commented 1 year ago

Hi, the new logics been implemented on #46, and on #47 been readapted to work with --merged flag. You right, I see some missing logics on #46 that need to be adjusted on https://github.com/marcocesarato/php-conventional-changelog/blob/92e3adbe75259f9a88047865324ae8e00cef7c66/src/Git/Repository.php#L115 and here https://github.com/marcocesarato/php-conventional-changelog/blob/92e3adbe75259f9a88047865324ae8e00cef7c66/src/Changelog.php#L370 I'll work on it.

adambalint-srg commented 1 year ago

Thanks, I can do it now with specifying from tag and new version manually, but I would be easier with the fixed logic :)

marcocesarato commented 1 year ago

Should be solved on 1.15.5, let me know if all works fine.

adambalint-srg commented 1 year ago

@marcocesarato Sorry, I could check it now. I've updated to the lastest version, and the situation is the same. I have this existing tag: v2.0.0-beta.10 I run the changelog generation with this command: vendor/bin/conventional-changelog --beta

It throws an error: fatal: ambiguous argument '0.0.0...HEAD': unknown revision or path not in the working tree.

It seems that it doesn't find the previous tag :/

adambalint-srg commented 1 year ago

@marcocesarato Maybe I can try to help with a PR tomorrow, or next week.

marcocesarato commented 1 year ago

@adambalint-srg I tried to replicate the error using the last version (v1.15.6). I created a tag v1.0.0-beta.1 on a repository and executed conventional-changelog --beta, the result been v1.0.0-beta.2. These tags were both on the same branch. I haven't tried it on various branches, but I don't believe it would be an issue.

Maybe I'm missing something else?

@marcocesarato Maybe I can try to help with a PR tomorrow, or next week.

Yes thanks, it would be greatly appreciated

adambalint-srg commented 1 year ago

@marcocesarato Strange, I also tried it on the same branch, the result is the same, it tries to find the 0.0.0 version, because it doesn't find alpha/beta tags. I've tried with debug, and found this situation:

https://github.com/marcocesarato/php-conventional-changelog/blob/8cb6ec0dd29f5f84c62eebf2fbc50634a4daad24/src/Git/Repository.php#L73-L74 The $tagsArray contains every tags:

array (  
  0 => 'v2.0.0-beta.10',
  1 => 'v2.0.0-beta.9',
  ...
  23 => 'v2.0.0-alpha.0',
  28 => 'master',
  29 => 'hotfixes'
)

https://github.com/marcocesarato/php-conventional-changelog/blob/8cb6ec0dd29f5f84c62eebf2fbc50634a4daad24/src/Git/Repository.php#L76 But in line 76 it filters this array, and find items which starts with v and doesn't contain -. With this all of our alpha/beta tags will be filtered out. And the $tagsFound array will be empty. Why this filter is there?

I've tried it with a clean repo, and yes, the version number is updated in composer.json (packageBump is turned off in my other project), and the changlog contains the correct version, but the history of the changelog entry is empty, and the generated diff link is from the version 0.0.0 https://github.com/ownser/repository/compare/0.0.0...v2.0.0-beta.11

With debug the situation is the same, in getLastTag it doesn't find the first tag, and it throws an error in console output:

fatal: ambiguous argument '0.0.0...HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

I've opened a PR for this, I think removing the - condition from regex won't cause problems.

marcocesarato commented 1 year ago

I found the problem, was in another part of the code where it wasn't implemented well for some cases. Released on 1.16.0. Let me know if now it works.

adambalint-srg commented 1 year ago

@marcocesarato I can confirm that it's OK now! Thanks for the fix :)