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

Add security advisory endpoint #21

Merged

Conversation

GuySartorelli
Copy link
Contributor

@GuySartorelli GuySartorelli commented Jun 24, 2022

Adds functionality to use the security advisories endpoint on the packagist api: https://packagist.org/apidoc#list-security-advisories

Draft because I want to know if this is an acceptable approach before I start adding tests.

@freekmurze
Copy link
Member

Seems good, please add tests

@GuySartorelli GuySartorelli marked this pull request as ready for review July 8, 2022 09:45
@GuySartorelli GuySartorelli force-pushed the pulls/main/add-advisories-endpoint branch from 02ea3e0 to 9b8d9e4 Compare July 8, 2022 11:14
@GuySartorelli
Copy link
Contributor Author

Now with tests (and fixed an unrelated one that was broken while I was at it). Please let me know if you need anything else from me.

@@ -84,6 +85,94 @@ public function getStatistics(): ?array
return $this->request('statistics.json');
}

/**
* Get security vulnerability advisories for specific packages and/or which have been updated since some timestamp.
Copy link
Member

Choose a reason for hiding this comment

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

We usually don't add such lengthy comments on how to use methods, but prefer methods that are obvious how you should use them.

We also don't like passing booleans to methods as this might hurt readability on the caller's side. Could you split this function into multiple other ones in which the use is clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is exactly the sort of thing I would have loved to be pointed out originally, when I hadn't yet written tests for the functionality as it's currently written. :p
I'll make the change, but really would have been nice to point this out when I was asking for exactly this sort of feedback originally.

Copy link
Contributor Author

@GuySartorelli GuySartorelli Jul 30, 2022

Choose a reason for hiding this comment

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

Split into two separate methods with no phpdocs

return $advisories;
}

private function filterAdvisories(array $advisories, array $packages): array
Copy link
Member

Choose a reason for hiding this comment

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

We don't use private. Change this to protected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*/
public function getAdvisories(array $packages = [], ?int $updatedSince = null, bool $filterByVersion = false): array
{
if (count($packages) === 0 && $updatedSince === null) {
Copy link
Member

Choose a reason for hiding this comment

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

The readability of this code can be improved.

Please avoid using && and split this into multiple smaller functions so the comments can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inline comments removed.
That specific && is not longer required. I've simply removed the ability to get all packages by udpatedsince because this PR is becoming burdonsome to develop. If someone wants that functionality they can add it separately afterward.

tests/Integration/PackagistClientTest.php Outdated Show resolved Hide resolved
@GuySartorelli GuySartorelli force-pushed the pulls/main/add-advisories-endpoint branch from 11a5aff to 88c5697 Compare July 30, 2022 04:30
@GuySartorelli GuySartorelli force-pushed the pulls/main/add-advisories-endpoint branch from 88c5697 to 4095d3b Compare July 30, 2022 04:32
@freekmurze freekmurze merged commit a8caf4f into spatie:main Aug 1, 2022
@freekmurze
Copy link
Member

Thanks!

@GuySartorelli GuySartorelli deleted the pulls/main/add-advisories-endpoint branch August 1, 2022 10:09
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.

2 participants