IonBazan / composer-diff

Compares composer.lock changes and generates Markdown report so you can use it in PR description.
https://packagist.org/packages/ion-bazan/composer-diff
MIT License
143 stars 6 forks source link

Fix generating links for gitlab repos in subgroups #3

Closed trakos closed 3 years ago

trakos commented 3 years ago

Hey,

first of all, thanks for the great package. I found a minor bug when using it with gitlab repositories.

Gitlab allows creating subgroups, for instance here is one of the gitlab repostiories: https://gitlab.com/gitlab-org/ci-cd/shared-runners/images/gcp/windows-containers . The source git path for that repo has many / signs:

git@gitlab.com:gitlab-org/ci-cd/shared-runners/images/gcp/windows-containers.git

The regex that is used to substitute package url does not allow for that, it only allows single / sign in path. As a result, it generated a line like that for me:

| istruct/component-developer       | Downgraded | 0.5.2 | dev-feature/tools a463df1 | [Compare](git@git.mydomain.example.com:istruct/component/developer/compare/0.5.2...a463df1)    |

As you can see, it left the git@ part in the comparison link, because preg_replace pattern didn't match anything.

I propose a simple fix that allows / in repository namespaces.

Additionally, comparison links across forks like:

https://gitlab.acme.org/IonBazan/package/compare/3.12.0...acme:3.12.1

don't work on gitlab for me, they have slightly different syntax:

https://gitlab.acme.org/IonBazan/package/compare/3.12.0...3.12.1?from_project_id=27069907

Unfortunately, we cannot generate it without knowing internal numerical project id, so I propose to simply return null in gitlab links generator when project namespaces don't match.

codecov[bot] commented 3 years ago

Codecov Report

Merging #3 (b2ab777) into master (ae1fca2) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##              master        #3   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       133       133           
===========================================
  Files             16        16           
  Lines            364       365    +1     
===========================================
+ Hits             364       365    +1     
Impacted Files Coverage Δ
src/Url/GitGenerator.php 100.00% <100.00%> (ø)
src/Url/GitlabGenerator.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ae1fca2...b2ab777. Read the comment docs.

IonBazan commented 3 years ago

Thanks @trakos! ❤️

trakos commented 3 years ago

I appreciate the quick merge @IonBazan ! 🙇 Your change definitely makes sense, it's better to give link to the target release.