Skip to content

New: Add security advisories endpoint. #86

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

Conversation

GuySartorelli
Copy link
Contributor

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.

@robbieaverill
Copy link
Collaborator

Thanks for the PR. This looks like a good new feature to me!

@GuySartorelli GuySartorelli force-pushed the pulls/master/add-advisory-endpoint branch from 66b2bcf to 92e4513 Compare July 8, 2022 09:45
@GuySartorelli GuySartorelli marked this pull request as ready for review July 8, 2022 09:46
@GuySartorelli
Copy link
Contributor Author

GuySartorelli commented Jul 8, 2022

Have added tests. Please let me know if you need anything else. I'm not familiar with the style of tests used in this package so I don't know if there's an established way to do end-to-end tests for example.

@robbieaverill
Copy link
Collaborator

The BDD tests are unit tests, an E2E test is usually done manually using the example scripts in this repository.

Thanks very much for the contribution, great work. I'll review it next week.

@robbieaverill
Copy link
Collaborator

By the way @GuySartorelli I've approved the CI workflow to run, there are a couple of failures

@GuySartorelli GuySartorelli force-pushed the pulls/master/add-advisory-endpoint branch from 92e4513 to 33e65a7 Compare July 9, 2022 06:51
@GuySartorelli
Copy link
Contributor Author

I wasn't sure how to run the tests locally so I was just kind of hoping it would pass... have now learned how to run them and have updated them. They pass locally now.

Copy link
Collaborator

@robbieaverill robbieaverill left a comment

Choose a reason for hiding this comment

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

This looks good, I think if you could update the doc blocks to be a little more descriptive that'd be great. I'd also suggest adding an example file, i.e.:

# File: examples/advisories.php
<?php

require __DIR__ . '/../vendor/autoload.php';

$client = new Packagist\Api\Client();
$package = $client->advisories(['monolog/monolog']);

var_export($package);

@@ -187,6 +189,88 @@ public function popular(int $total): array
return array_slice($results, 0, $total);
}

/**
* Get a list of known security vulnerability advisories
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this docblock would benefit from some extra information describing what the $updatedSince and $filterByVersion arguments are for. It's not immediately obvious to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the phpdoc to be more descriptive

/**
* Get a list of known security vulnerability advisories
*
* @param array $packages
Copy link
Collaborator

Choose a reason for hiding this comment

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

My initial instinct when testing this was to call $client->advisories('monolog/monolog'). I think it's fine to enforce an array of package names here (maybe add this as a description on this argument). I then thought it might be nice to be able to access advisories from the Package class, i.e. $package->advisories(), but the Package class doesn't have client awareness so it would require making the AbstractResult classes aware of the client. I don't think it's worth it, but it would be nice to have that accessor method.

(Not asking for changes here, just voicing my thoughts while testing)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I thought about allowing Package values in the array, but all of the other methods that accept a package as an argument only accept the string names, so I figured it made sense to be consistent and do the same here.

Maybe a future enhancement could be to change all of those to accept Package|string.

@GuySartorelli GuySartorelli force-pushed the pulls/master/add-advisory-endpoint branch from 33e65a7 to b9f74e2 Compare July 30, 2022 04:01
@GuySartorelli
Copy link
Contributor Author

Requested changes made. I've left the phpdoc for the results either missing or sparse because that seems to be the standard for result classes but let me know if you'd like those to have some explanation as well... but generally I'd expect anyone who wants to use this to already have checked out the packagist docs which show exactly what sort of result the api returns.

@robbieaverill robbieaverill merged commit 0c5c7e2 into KnpLabs:master Aug 8, 2022
@robbieaverill
Copy link
Collaborator

@GuySartorelli I've included this in v2.0.0-rc3. If this release looks good to you I'll tag v2.0.0. Thanks for the PR!

@GuySartorelli GuySartorelli deleted the pulls/master/add-advisory-endpoint branch August 8, 2022 22:09
@GuySartorelli
Copy link
Contributor Author

GuySartorelli commented Aug 8, 2022

Awesome, thank you. I'll try to give the release a proper look on the weekend. Looks good at a cursory glance though

@GuySartorelli
Copy link
Contributor Author

@robbieaverill Sorry it's taken me so long to get back to you - the RC looks great!

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