-
Notifications
You must be signed in to change notification settings - Fork 7
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
Issues/451 Add advisory information to a commit messages #459
base: latest
Are you sure you want to change the base?
Conversation
build-conflicts.php
Outdated
|
||
$addedAdvisories = []; | ||
foreach ($getAdvisories() as $advisory) { | ||
if (in_array($advisory->package->packageName, $oldConflictPackages, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this would only list new packages, but not new versions of those packages 🤔
A bit of a more elaborate intersection mechanism is needed here, perhaps reading the current composer.json
into a set of exclusion ranges (we already have value objects for that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, okay, thank you. I'll try to tackle it this weekend 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to push it, don't worry! We can also try discussing this 1-on-1 in the coming weeks, if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and I got overwhelmed with stuff. Sorry for late response. Yes, 1-on-1 would be great as I'm not sure I understand what is needed to be done.
For example we have an old set of ranges "amphp/http-client": "<1|>=4,<4.4"
and new set of ranges that looks like so "amphp/http-client": ">=4,<4.4|>=4.6"
,
where >=4.6
is new and <1
was deleted/retracted.
I should mention both <1
and >=4.6
in a commit message, right ? Basically everything that is not "overlapping" between the two 🤔
@azjezz thank you for suggestions! It was a bit hard to wrap my head around some PSL stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
been staring at this whole evening. An elaborate intersection mechanism is, of course, possible, but looks overly complex(?) 🤔
If that is for human to read, could we just do something dumb like this:
- get old and fresh json files with conflicts
- if package is completely new, mark it as such
- if package exists in both files, try to compare string values.
- if strings are different, then add it, for example, like so
"amphp/http-client" updated from "<1|>=4,<4.4" to ">=4,<4.4|>=4.6"
And finally in commit message, we'd have it
Newly added:
Package: "amphp/http" "<1.0.1"
Summary: "Potential SQL injection vector"
URI: "https://github.com/...."
Updated:
"amphp/http-client" updated from "<1|>=4,<4.4" to ">=4,<4.4|>=4.6"
Summary: "Potential SQL injection vector"
URI: "https://github.com/...."
Deleted (completely):
"foo/bar" ">1.2"
Summary: "Potential SQL injection vector"
URI: "https://github.com/...."
Just thinking out loud 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An elaborate intersection mechanism is, of course, possible, but looks overly complex(?) thinking
We already have that.
- read current range
- read advisory
- compare advisory with current range: if it is already fully included, then consider it "done"
- otherwise, add it to the bucket of "advisories that will change
composer.json
"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed briefly on twitter:
- read current
composer.json
into alist<Component>
, where eachComponent
has its associated dependency exclusion range parsed (we already have most of that written) - read the individual advisories from their respective sources - keep a link to the source in each of the read advisories
- compare the
list<Component>
to thelist<Advisory>
, and determine whichAdvisory
instances are NOT fully contained inlist<Component>
- use the resulting data to produce the commit message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some comments that should help you with using PSL instead of stdlib, let me know if you need help with anything else.
build-conflicts.php
Outdated
@@ -34,6 +34,11 @@ | |||
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromGithubApi; | |||
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromMultipleSources; | |||
|
|||
use function array_keys; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use function array_keys; | |
use Psl\Vec; |
$keys = Vec\keys($array);
build-conflicts.php
Outdated
@@ -34,6 +34,11 @@ | |||
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromGithubApi; | |||
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromMultipleSources; | |||
|
|||
use function array_keys; | |||
use function count; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use function count; | |
use Psl\Iter; |
$count = Iter\count($iterable);
@@ -34,6 +34,11 @@ | |||
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromGithubApi; | |||
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromMultipleSources; | |||
|
|||
use function array_keys; | |||
use function count; | |||
use function file_get_contents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use function file_get_contents; | |
use Psl\Filesystem; |
$content = Filesystem\read_file($filename);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
build-conflicts.php
Outdated
use function array_keys; | ||
use function count; | ||
use function file_get_contents; | ||
use function in_array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use function in_array; | |
use Psl\Iter; |
$contains = Iter\contains($array, $value);
$contains_key = Iter\contains_key($array, $key);
build-conflicts.php
Outdated
use function count; | ||
use function file_get_contents; | ||
use function in_array; | ||
use function json_decode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use function json_decode; | |
use Psl\Json; |
$result = Json\decode($json);
or better:
use Psl\Json;
use Psl\Type;
$result = Json\typed($json, Type\shape([
'foo' => Type\string(),
'bar' => Type\vec(Type\int()), // vec<T> is list<T>
'baz' => Type\dict(Type\int(), Type\string()), // dict<Tk, Tv> is array<Tk, Tv>
]);
…ersions represented as strings
@@ -34,6 +34,11 @@ | |||
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromGithubApi; | |||
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromMultipleSources; | |||
|
|||
use function array_keys; | |||
use function count; | |||
use function file_get_contents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
@@ -33,7 +35,7 @@ private function __construct() | |||
*/ | |||
public static function fromString(string $versionConstraint): self | |||
{ | |||
$constraintString = $versionConstraint; | |||
$constraintString = Str\replace($versionConstraint, ' ', ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one handles spaces in boundaries, coming from github advisories, not super critical but annoying
@@ -142,8 +144,12 @@ public function mergeWith(self $other): self | |||
)); | |||
} | |||
|
|||
private function contains(self $other): bool | |||
public function contains(self $other): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how to do it any other was 🤔
} | ||
|
||
/** | ||
* @return array<string, mixed> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a little push, how do I describe type for this ?
ERROR: MixedInferredReturnType - test/RoaveTest/SecurityAdvisories/Helper/ConstraintsMapTest.php:69:16 - Providers must return iterable<array-key, array<array-key, mixed>>, possibly different array<string, mixed> provided (see https://psalm.dev/047)
* @return array<string, mixed>
ERROR: MixedInferredReturnType - test/RoaveTest/SecurityAdvisories/Helper/ConstraintsMapTest.php:148:16 - Providers must return iterable<array-key, array<array-key, mixed>>, possibly different array<string, mixed> provided (see https://psalm.dev/047)
* @return array<string, mixed>
…+00:00" Original commit: "FriendsOfPHP/security-advisories@e14352c"
This patch adds advisory information when advisory is added/updated
Fixes #451
Example of how it will look like.
composer.json has conflict
"snipe/snipe-it": "<5.3.11|>=6.0.0-RC-1,<=6.0.0-RC-5",
after
php build-conflicts.php
it will become"snipe/snipe-it": "<5.4.3|>=6.0.0-RC-1,<=6.0.0-RC-5",
Commit message will be the following: