-
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
Open
slash3b
wants to merge
25
commits into
Roave:latest
Choose a base branch
from
slash3b:issues/451
base: latest
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2876480
dirty crude implementation
slash3b b4069af
stuck with PSL, Psalm and.. everything
slash3b c21c6d7
friends of php test is fixed
slash3b 6e7fcda
components fixed
slash3b 03034c0
advisory tests fixes
slash3b 4271453
multiple sources fix
slash3b f35e700
fuck yes! unit tests are no longer broken
slash3b a89685b
some polishing ftw
slash3b 3f0c1cb
phpcs automatic fixes
slash3b fcb9dda
a bit stuck
slash3b 4cd6eae
deleted bad comment
slash3b 08a02eb
crude PoC
slash3b 9431fb9
constraints map implemented (?) but requires test
slash3b e3c11e4
test for constraint map
slash3b 0552bf2
code sniffer fixes
slash3b 0339ba2
code sniffer satisfied for now
slash3b c528ad8
build-conflicts changes
slash3b b89a3f4
build-conflicts cs fix
slash3b 03d5e8d
tests are good to go now. Had to add "source" to all Advisory initial…
slash3b bb88c3d
no need for asserts for now
slash3b 72e7e73
build-conflict psalm resolved for now (?)
slash3b b8e40fb
psalm fixes
slash3b 18bd74a
how about now ?
slash3b 9be9605
remove whitespace coming from github
slash3b 3638683
for `contains` in VersionConstraint.php lets try to compare complex v…
slash3b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Roave\SecurityAdvisories\Helper; | ||
|
||
use Roave\SecurityAdvisories\Advisory; | ||
use Roave\SecurityAdvisories\VersionConstraint; | ||
|
||
use function array_key_exists; | ||
use function Psl\Str\split; | ||
|
||
final class ConstraintsMap | ||
{ | ||
/** @var array<string, array<VersionConstraint>> $map */ | ||
private array $map; | ||
|
||
/** | ||
* @param array<string, array<VersionConstraint>> $conflicts | ||
*/ | ||
private function __construct(array $conflicts) | ||
{ | ||
$this->map = $conflicts; | ||
} | ||
|
||
/** | ||
* @param array<string, string> $packageConflictsParsedData | ||
* | ||
* @return ConstraintsMap | ||
*/ | ||
public static function fromArray(array $packageConflictsParsedData): self | ||
{ | ||
$packageConflicts = []; | ||
|
||
foreach ($packageConflictsParsedData as $referenceName => $constraintsString) { | ||
$packageConstraints = []; | ||
foreach (split($constraintsString, '|') as $range) { | ||
$packageConstraints[] = VersionConstraint::fromString($range); | ||
} | ||
|
||
$packageConflicts[$referenceName] = $packageConstraints; | ||
} | ||
|
||
return new self($packageConflicts); | ||
} | ||
|
||
/** | ||
* @param array<Advisory> $advisoriesToFilter | ||
* | ||
* @return array<Advisory> | ||
*/ | ||
public function advisoriesDiff(array $advisoriesToFilter): array | ||
{ | ||
$filteredAdvisories = []; | ||
|
||
foreach ($advisoriesToFilter as $advisoryToFilter) { | ||
$pkgNameKey = $advisoryToFilter->package->packageName; | ||
|
||
$isNewAdvisory = ! array_key_exists($pkgNameKey, $this->map); | ||
|
||
if ($isNewAdvisory) { | ||
$filteredAdvisories[] = $advisoryToFilter; | ||
continue; | ||
} | ||
|
||
$isUpdateAdvisory = $this->isAdvisoryUpdate($pkgNameKey, $advisoryToFilter); | ||
|
||
if (! $isUpdateAdvisory) { | ||
continue; | ||
} | ||
|
||
$filteredAdvisories[] = $advisoryToFilter; | ||
} | ||
|
||
return $filteredAdvisories; | ||
} | ||
|
||
private function isAdvisoryUpdate(string $packageName, Advisory $advisoryToCheck): bool | ||
{ | ||
$packageConstraints = $this->map[$packageName]; | ||
|
||
foreach ($advisoryToCheck->getVersionConstraints() as $advisoryConstraint) { | ||
$included = false; | ||
foreach ($packageConstraints as $pkgConstraint) { | ||
if ($pkgConstraint->contains($advisoryConstraint)) { | ||
$included = true; | ||
break; | ||
} | ||
} | ||
|
||
if (! $included) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Roave\SecurityAdvisories; | ||
|
||
// value object | ||
use Psl\Type; | ||
|
||
final class Source | ||
{ | ||
/** @var non-empty-string $summary */ | ||
public string $summary; | ||
|
||
/** @var non-empty-string $uri */ | ||
public string $uri; | ||
|
||
/** | ||
* @param non-empty-string $summary | ||
* @param non-empty-string $uri | ||
*/ | ||
private function __construct(string $summary, string $uri) | ||
{ | ||
$this->summary = $summary; | ||
$this->uri = $uri; | ||
} | ||
|
||
public static function new(string $summary, string $uri): self | ||
{ | ||
return new self(Type\non_empty_string()->assert($summary), Type\non_empty_string()->assert($uri)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
$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!