IonBazan / composer-diff

Compares composer.lock changes and generates Markdown report so you can use it in PR description.

Home Page:https://packagist.org/packages/ion-bazan/composer-diff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Drupal packages with links and diffs

davereid-pfg opened this issue · comments

It would be nice to support Drupal.org's packages with composer diff links and diffs, currently they are not supported.

@davereid-pfg great idea! Seems that Dupal.org is using self-hosted gitlab so it should be quite easy to implement.
Can you share a few packages we could add to tests to check if it's working correctly?

Ha, was hoping I'd find this issue open here. @IonBazan I don't think it will be quite so simple, as Drupal package versions don't necessarily strictly adhere to semver. Drupal.org supports semver now, but it is optional.

Traditionally, packages would be tagged with something like 8.x-1.11 vs 1.11.0. However, Drupal.org's Composer packagist has a facade built in that allows you to require packages not following semver as if you were using semver (i.e. composer require drupal/address:^1 still gets you the latest in the 8.x-1.x release series, in this case 8.x-1.11.

I only quickly glanced through your implementation, and I'm not familiar with Composer's native version comparison capabilities to know whether or not any of your comparator logic would need to be changed to accommodate.

Below are some examples of .json and .lock entries for both types of package tags.

Examples

Non-semver

composer.json:

    "require": {
        "drupal/address": "^1.10",
    }

composer.lock:

        {
            "name": "drupal/address",
            "version": "1.11.0",
            "source": {
                "type": "git",
                "url": "https://git.drupalcode.org/project/address.git",
                "reference": "8.x-1.11"
            },
            "dist": {
                "type": "zip",
                "url": "https://ftp.drupal.org/files/projects/address-8.x-1.11.zip",
                "reference": "8.x-1.11",
                "shasum": "1cb40fb1a43e88041b888ac8fb6aa77a45ac85fb"
            },
            "require": {
                "commerceguys/addressing": "^1.4.0",
                "drupal/core": "^9.2 || ^10",
                "php": "^7.3 || ^8.0"
            },
            "require-dev": {
                "drupal/token": "^1.0"
            },
            "type": "drupal-module",
            "extra": {
                "drupal": {
                    "version": "8.x-1.11",
                    "datestamp": "1659989858",
                    "security-coverage": {
                        "status": "covered",
                        "message": "Covered by Drupal's security advisory policy"
                    }
                }
            },
            "notification-url": "https://packages.drupal.org/8/downloads",
            "license": [
                "GPL-2.0-or-later"
            ],
            "authors": [
                {
                    "name": "bojanz",
                    "homepage": "https://www.drupal.org/user/86106"
                },
                {
                    "name": "Centarro",
                    "homepage": "https://www.drupal.org/user/3661446"
                },
                {
                    "name": "dww",
                    "homepage": "https://www.drupal.org/user/46549"
                },
                {
                    "name": "googletorp",
                    "homepage": "https://www.drupal.org/user/386230"
                },
                {
                    "name": "jsacksick",
                    "homepage": "https://www.drupal.org/user/972218"
                },
                {
                    "name": "mglaman",
                    "homepage": "https://www.drupal.org/user/2416470"
                },
                {
                    "name": "rszrama",
                    "homepage": "https://www.drupal.org/user/49344"
                }
            ],
            "description": "Provides functionality for storing, validating and displaying international postal addresses.",
            "homepage": "http://drupal.org/project/address",
            "support": {
                "source": "https://git.drupalcode.org/project/address"
            }
        },

Semver

composer.json:

    "require": {
        "drupal/webform": "^6",
    }

composer.lock:

        {
            "name": "drupal/webform",
            "version": "6.1.4",
            "source": {
                "type": "git",
                "url": "https://git.drupalcode.org/project/webform.git",
                "reference": "6.1.4"
            },
            "dist": {
                "type": "zip",
                "url": "https://ftp.drupal.org/files/projects/webform-6.1.4.zip",
                "reference": "6.1.4",
                "shasum": "b1c27c2a210670b6d149cdd92cbb37100b19cf64"
            },
            "require": {
                "drupal/core": "^8.8 || ^9"
            },
            "require-dev": {
                "drupal/address": "~1.0",
                "drupal/bootstrap": "~3.0",
                "drupal/captcha": "~1.0",
                "drupal/chosen": "~3.0",
                "drupal/clientside_validation": "*",
                "drupal/clientside_validation_jquery": "*",
                "drupal/devel": "*",
                "drupal/entity": "~1.0",
                "drupal/entity_print": "*",
                "drupal/gnode": "*",
                "drupal/group": "*",
                "drupal/jquery_ui": "~1.0",
                "drupal/jquery_ui_checkboxradio": "*",
                "drupal/jquery_ui_datepicker": "~1.0",
                "drupal/lingotek": "~3.0",
                "drupal/mailsystem": "~4.0",
                "drupal/paragraphs": "~1.0",
                "drupal/select2": "~1.0",
                "drupal/smtp": "~1.0",
                "drupal/styleguide": "~2.0",
                "drupal/telephone_validation": "~2.0",
                "drupal/token": "*",
                "drupal/variationcache": "~1.0",
                "drupal/webform-webform_group": "*",
                "drupal/webform_access": "*",
                "drupal/webform_attachment": "*",
                "drupal/webform_clientside_validation": "*",
                "drupal/webform_devel": "*",
                "drupal/webform_entity_print": "*",
                "drupal/webform_node": "*",
                "drupal/webform_options_limit": "*",
                "drupal/webform_scheduled_email": "*",
                "drupal/webform_share": "*",
                "drupal/webform_ui": "*"
            },
            "suggest": {
                "drupal/jquery_ui_checkboxradio": "Provides jQuery UI Checkboxradio library. Required by the Webform jQueryUI Buttons module. The Webform jQueryUI Buttons module is deprecated because jQueryUI is no longer maintained.",
                "drupal/jquery_ui_datepicker": "Provides jQuery UI Datepicker library. Required to support datepickers. The Webform jQueryUI Datepicker module is deprecated because jQueryUI is no longer maintained."
            },
            "type": "drupal-module",
            "extra": {
                "drupal": {
                    "version": "6.1.4",
                    "datestamp": "1673535467",
                    "security-coverage": {
                        "status": "covered",
                        "message": "Covered by Drupal's security advisory policy"
                    }
                },
                "drush": {
                    "services": {
                        "drush.services.yml": "^9 || ^10"
                    }
                }
            },
            "notification-url": "https://packages.drupal.org/8/downloads",
            "license": [
                "GPL-2.0-or-later"
            ],
            "authors": [
                {
                    "name": "Jacob Rockowitz (jrockowitz)",
                    "homepage": "https://www.drupal.org/u/jrockowitz",
                    "role": "Maintainer"
                },
                {
                    "name": "Contributors",
                    "homepage": "https://www.drupal.org/node/7404/committers",
                    "role": "Contributor"
                },
                {
                    "name": "Liam Morland",
                    "homepage": "https://www.drupal.org/user/493050"
                },
                {
                    "name": "quicksketch",
                    "homepage": "https://www.drupal.org/user/35821"
                },
                {
                    "name": "torotil",
                    "homepage": "https://www.drupal.org/user/865256"
                }
            ],
            "description": "Enables the creation of webforms and questionnaires.",
            "homepage": "https://drupal.org/project/webform",
            "support": {
                "source": "https://git.drupalcode.org/project/webform",
                "issues": "https://www.drupal.org/project/issues/webform?version=8.x",
                "docs": "https://www.drupal.org/docs/8/modules/webform",
                "forum": "https://drupal.stackexchange.com/questions/tagged/webform"
            }
        },

I had started work on this with a custom class that extended the existing Gitlab class and it was showing promise of working, I'll see if I can try and push up what I had to a PR.

I've continued @davereid-pfg's fine work in a fork of my own. The trick to getting it working seemed to be to use the dist or source version, rather than the package version, which makes sense when you think about it I reckon.