Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automatic_updates
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
automatic_updates
Merge requests
!681
Issue
#3311229
: Check composer minimum stability when doing an update
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3311229
: Check composer minimum stability when doing an update
issue/automatic_updates-3311229:3311229-check-composer-minimum
into
8.x-2.x
Overview
76
Commits
32
Pipelines
1
Changes
7
Merged
Yash Rode
requested to merge
issue/automatic_updates-3311229:3311229-check-composer-minimum
into
8.x-2.x
2 years ago
Overview
76
Commits
32
Pipelines
1
Changes
7
Expand
0
0
Merge request reports
Compare
8.x-2.x
version 26
7f92d17e
2 years ago
version 25
438e4905
2 years ago
version 24
52bca420
2 years ago
version 23
b7e299d0
2 years ago
version 22
d7d08f0c
2 years ago
version 21
5b71fae6
2 years ago
version 20
b7a02df1
2 years ago
version 19
bd51c585
2 years ago
version 18
22338abe
2 years ago
version 17
ed7a3f20
2 years ago
version 16
df1cbf67
2 years ago
version 15
947d7465
2 years ago
version 14
fc17f8d6
2 years ago
version 13
6f11135b
2 years ago
version 12
17a61d44
2 years ago
version 11
a930bbab
2 years ago
version 10
80be08ae
2 years ago
version 9
d5007196
2 years ago
version 8
c7b51d68
2 years ago
version 7
114af9a2
2 years ago
version 6
5df190e3
2 years ago
version 5
933ddddc
2 years ago
version 4
d862bbcf
2 years ago
version 3
f030433c
2 years ago
version 2
a4af7eed
2 years ago
version 1
83dde309
2 years ago
8.x-2.x (base)
and
latest version
latest version
7f92d17e
32 commits,
2 years ago
version 26
7f92d17e
32 commits,
2 years ago
version 25
438e4905
30 commits,
2 years ago
version 24
52bca420
29 commits,
2 years ago
version 23
b7e299d0
26 commits,
2 years ago
version 22
d7d08f0c
25 commits,
2 years ago
version 21
5b71fae6
24 commits,
2 years ago
version 20
b7a02df1
22 commits,
2 years ago
version 19
bd51c585
21 commits,
2 years ago
version 18
22338abe
20 commits,
2 years ago
version 17
ed7a3f20
19 commits,
2 years ago
version 16
df1cbf67
18 commits,
2 years ago
version 15
947d7465
17 commits,
2 years ago
version 14
fc17f8d6
16 commits,
2 years ago
version 13
6f11135b
15 commits,
2 years ago
version 12
17a61d44
12 commits,
2 years ago
version 11
a930bbab
11 commits,
2 years ago
version 10
80be08ae
10 commits,
2 years ago
version 9
d5007196
9 commits,
2 years ago
version 8
c7b51d68
8 commits,
2 years ago
version 7
114af9a2
7 commits,
2 years ago
version 6
5df190e3
6 commits,
2 years ago
version 5
933ddddc
5 commits,
2 years ago
version 4
d862bbcf
4 commits,
2 years ago
version 3
f030433c
3 commits,
2 years ago
version 2
a4af7eed
2 commits,
2 years ago
version 1
83dde309
1 commit,
2 years ago
7 files
+
212
−
11
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
package_manager/src/Validator/ComposerMinimumStabilityValidator.php
0 → 100644
+
104
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\package_manager\Validator
;
use
Composer\Semver\Semver
;
use
Composer\Semver\VersionParser
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Drupal\package_manager
\ComposerInspector
;
use
Drupal\package_manager
\Event\PreRequireEvent
;
use
Drupal\package_manager
\PathLocator
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
/**
* Checks that the (about to be) installed packages meet the minimum stability.
*
* @internal
* This is an internal part of Package Manager and may be changed or removed
* at any time without warning. External code should not interact with this
* class.
*/
final
class
ComposerMinimumStabilityValidator
implements
EventSubscriberInterface
{
use
StringTranslationTrait
;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected
PathLocator
$pathLocator
;
/**
* The Composer inspector service.
*
* @var \Drupal\package_manager\ComposerInspector
*/
protected
ComposerInspector
$inspector
;
/**
* Constructs a ComposerMinimumStabilityValidator object.
*
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* @param \Drupal\package_manager\ComposerInspector $inspector
* The Composer inspector service.
*/
public
function
__construct
(
PathLocator
$path_locator
,
ComposerInspector
$inspector
)
{
$this
->
pathLocator
=
$path_locator
;
$this
->
inspector
=
$inspector
;
}
/**
* Validates composer minimum stability.
*
* @param \Drupal\package_manager\Event\PreRequireEvent $event
* The stage event.
*/
public
function
validateMinimumStability
(
PreRequireEvent
$event
):
void
{
$dir
=
$this
->
pathLocator
->
getProjectRoot
();
$minimum_stability
=
$this
->
inspector
->
getConfig
(
'minimum-stability'
,
$dir
);
$requested_packages
=
$event
->
getRuntimePackages
();
foreach
(
$requested_packages
as
$package_name
=>
$version
)
{
// In the root composer.json, a stability flag can also be specified. They
// take the form @code constraint@stability @endcode. A stability flag
// allow the project owner to deviate from the minimum-stability setting.
// @see https://getcomposer.org/doc/04-schema.md#package-links
// @see \Composer\Package\Loader\RootPackageLoader::extractStabilityFlags()
if
(
str_contains
(
$version
,
'@'
))
{
continue
;
}
$stability
=
VersionParser
::
parseStability
(
$version
);
// Because drupal/core prefers to not depend on composer/composer we need
// to compare two versions that are identical except for stability to
// determine if the package stability is less that the minimum stability.
if
(
Semver
::
satisfies
(
"1.0.0-
$stability
"
,
"< 1.0.0-
$minimum_stability
"
))
{
$event
->
addError
([
$this
->
t
(
"<code>@package_name</code>'s requested version @package_version is less stable (@package_stability) than the minimum stability (@minimum_stability) required in @file."
,
[
'@package_name'
=>
$package_name
,
'@package_version'
=>
$version
,
'@package_stability'
=>
$stability
,
'@minimum_stability'
=>
$minimum_stability
,
'@file'
=>
$this
->
pathLocator
->
getProjectRoot
()
.
'/composer.json'
,
]
),
]);
}
}
}
/**
* {@inheritdoc}
*/
public
static
function
getSubscribedEvents
():
array
{
return
[
PreRequireEvent
::
class
=>
'validateMinimumStability'
,
];
}
}
Loading