Skip to content
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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

mayur-sose
Copy link

No description provided.

@mayur-sose mayur-sose self-assigned this Dec 11, 2024
@mayur-sose mayur-sose removed their assignment Dec 11, 2024
Copy link
Contributor

@TravisCarden TravisCarden left a 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.

Comment on lines +23 to +47
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);
}
}
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function update_packages_yaml($filePath) {
function update_packages_yaml(string $filePath) {

@Raksha-Bharuka Raksha-Bharuka added the enhancement New feature or request label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants