-
Notifications
You must be signed in to change notification settings - Fork 21
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
Script to update package.yml using dependabot #641
base: develop
Are you sure you want to change the base?
Conversation
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.
Looks good. I made a few minor suggestions, but I won't insist on them.
function get_latest_version($packageName) { | ||
$client = new Client(); | ||
$url = "https://repo.packagist.org/p/{$packageName}.json"; | ||
|
||
try { | ||
$response = $client->get($url); | ||
$data = json_decode($response->getBody(), TRUE); | ||
|
||
$versions = array_keys($data['packages'][$packageName]); | ||
usort($versions, 'version_compare'); | ||
|
||
$latestVersion = end($versions); | ||
|
||
// Extract major.minor version (e.g., "13.3.3" becomes "13.x") | ||
$versionParts = explode('.', $latestVersion); | ||
if (count($versionParts) > 1) { | ||
return $versionParts[0] . '.x'; | ||
} | ||
|
||
return NULL; | ||
} | ||
catch (RequestException $e) { | ||
return get_latest_version_from_drupal_org($packageName); | ||
} | ||
} |
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 would be much more readable if you would extract the Packagist part this into a separate function just like you did with get_latest_version_from_drupal_org()
. Consider how much clearer this would be, for example:
function get_latest_version($packageName) {
return get_latest_version_from_packagist($packageName)
?? get_latest_version_from_drupal_org($packageName);
}
* @return string|null | ||
* The latest version string, or NULL if not found. | ||
*/ | ||
function get_latest_version($packageName) { |
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.
function get_latest_version($packageName) { | |
function get_latest_version(string $packageName) { |
* @return string|null | ||
* The latest version string, or NULL if not found. | ||
*/ | ||
function get_latest_version_from_drupal_org($packageName) { |
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.
function get_latest_version_from_drupal_org($packageName) { | |
function get_latest_version_from_drupal_org(string $packageName) { |
* @return bool | ||
* TRUE if it is a major update, FALSE otherwise. | ||
*/ | ||
function is_major_update($currentVersion, $latestVersion) { |
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.
function is_major_update($currentVersion, $latestVersion) { | |
function is_major_update(?string $currentVersion, ?string $latestVersion) { |
* @param string $filePath | ||
* The path to the YAML file. | ||
*/ | ||
function update_packages_yaml($filePath) { |
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.
function update_packages_yaml($filePath) { | |
function update_packages_yaml(string $filePath) { |
No description provided.