Skip to content

Conversation

@eXistenZNL
Copy link

@eXistenZNL eXistenZNL commented Sep 4, 2025

Context

This change is needed because Composer v1 is no longer available as of September 1st, apparently this also means that the Packagist API got cleaned up and some endpoints were removed. It turns out that https://repo.packagist.org is no longer available which was still heavily used in this codebase.

For more info, see https://blog.packagist.com/packagist-org-shutdown-of-composer-1-x-support-postponed-to-september-1st-2025/ for more information on deprecating composer v1.

What has been done

  • Updated the tests to reflect the Packagist v2 API
  • Updated the code to deal with the Packagist v2 API
  • Tried to keep the codestyle as consistent as possible with the existing codebase without an existing codestyle or linter.

How to test

Broken behaviour:

  • Against any repository, run the current released version of php-libyear.
  • See that all columns but the current version are empty.
  • See that a total of 0.00 libyears is calculated.

Fixed behaviour:

  • Against any repository, run the version of php-libyear from this PR.
  • See that all columns are filled out with the correct data as expected.
  • See that (very likely) a total of more than 0.00 libyears is calculated.

SteveDesmond-ca and others added 2 commits August 27, 2025 19:53
Bump guzzlehttp/guzzle from 7.9.3 to 7.10.0

Bumps [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) from 7.9.3 to 7.10.0.
- [Release notes](https://github.com/guzzle/guzzle/releases)
- [Changelog](https://github.com/guzzle/guzzle/blob/7.10/CHANGELOG.md)
- [Commits](guzzle/guzzle@7.9.3...7.10.0)

---
updated-dependencies:
- dependency-name: guzzlehttp/guzzle
  dependency-version: 7.10.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Bump composer/semver from 3.4.3 to 3.4.4

Bumps [composer/semver](https://github.com/composer/semver) from 3.4.3 to 3.4.4.
- [Release notes](https://github.com/composer/semver/releases)
- [Changelog](https://github.com/composer/semver/blob/main/CHANGELOG.md)
- [Commits](composer/semver@3.4.3...3.4.4)

---
updated-dependencies:
- dependency-name: composer/semver
  dependency-version: 3.4.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
This change is needed because the v1 repository on repo.packagist.org
is no longer available and thus this tool can no longer fetch meta
data from it and thus calculate libyears from it, rendering it useless.
@eXistenZNL
Copy link
Author

@WyriHaximus @SteveDesmond-ca @greg0ire @prajapati-kaushik did one of you already find the time to have a look at this? It would be greatly apreciated, since the latest release is broken 👍

@SteveDesmond-ca
Copy link
Member

It's on my radar, can hopefully get a new release out this week.

Comment on lines 28 to 36
$response = $this->http_client->request('GET', "$url/packages.json");
$result = json_decode($response->getBody()->getContents(), true) ?? [];

// For the new packagist.org, override the deprecated metadata-url
if ($url === 'https://packagist.org') {
return new Repository($url, '/packages/%package%.json');
}

return new Repository($url, array_key_exists('metadata-url', $result) ? $result['metadata-url'] : null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks -- everything else looks good, but I want to think a little more on this part...it feels off, but it's also been years since I've really worked with this app's code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah makes sense. If I find the time I will have a look as well if we need that URL compare at all.

@SteveDesmond-ca
Copy link
Member

I did a deep-dive into this today.

It turns out the libyear app is already using the v2 API (as evidenced by the /p2/ in the URL. Packagist's API documentation thoroughly references the URL that this project is already using.

If you've hit a specific bug, feel free to add an issue.

@eXistenZNL
Copy link
Author

eXistenZNL commented Sep 25, 2025

Yes I've hit a specific bug indeed, which can be reproduced by following the exact steps I outlined above, and can be resolved by merging this PR.

Please see this screen recording if you can't or won't follow the outlined steps by yourself. Here you can see I run libyear against it's own repo to determine the freshness of this project, both with the latest version from master and my patched branch:

In conclusion, the current release of php-libyear is still very much broken.

I hope to find the time today to respond to your claim that the v2 URLS are already used if I can find the time.

Signing off for now, @eXistenZNL.

@annard
Copy link

annard commented Sep 25, 2025

This is a useful fix, shame to throw it away...

@SteveDesmond-ca
Copy link
Member

I dug a little deeper, as I would agree that the current version does not work with Packagist, which is likely the majority of use cases.

The issue is that, at some point recently (maybe when they shut down v1 support), Packagist switched to using an absolute URL for their metadata pattern, where it had always up until that point been a relative one. The code can't handle that absolute part: it's just doing naive string concatenation.

This PR works in the specific case with Packagist because it hardcodes an override for the new default host to use a relative URL. If a user has anything other than Packagist in their project, and that repo has an absolute URL for its metadata pattern, the same issue will occur, even with this PR.

#155 has been created to track this and a new release with a fix for that should hopefully be out by the end of the week.

For completeness, since it was mentioned again, the documentation URL provided before (https://packagist.org/apidoc#get-package-data) has 3 sub-headers in that section that show the different ways to get package info. /p2/%package%.json is for v2, /p/%package%.json is v1, and /packages/%package%.json is recommended against if /p2/ is sufficient.

@eXistenZNL
Copy link
Author

eXistenZNL commented Sep 25, 2025

Ah @SteveDesmond-ca thanks for having another look at this!

I hope I didn't came across as too stern in my latest response, I was just disappointed that this was closed whilst the issue still persisted.

For now, I think there is not much more for me to add or investigate, and and your own comment explains it all.

Feel free to pick my changes directly or use them as inspiration for a fix from your side.

Good luck with the new release,

@eXistenZNL

@SteveDesmond-ca
Copy link
Member

v3.0.0 just got released with this fix along with a couple small features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants