From 2b406d054528585b8f4a7f6689aee9b39324d5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Colombaro?= Date: Mon, 14 Feb 2022 02:59:58 +0100 Subject: [PATCH] Add shasum value into generated packages Close #1 --- src/ReleaseSources/WPDotOrgAPI.php | 13 ++++- tests/ReleaseSources/WPDotOrgAPITest.php | 6 +++ tests/resources/source-composer.json | 64 ++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tests/resources/source-composer.json diff --git a/src/ReleaseSources/WPDotOrgAPI.php b/src/ReleaseSources/WPDotOrgAPI.php index 4dadd087..265417fd 100644 --- a/src/ReleaseSources/WPDotOrgAPI.php +++ b/src/ReleaseSources/WPDotOrgAPI.php @@ -32,10 +32,16 @@ protected function packageFromObject(stdClass $release): PackageInterface ->withVersion($release->version); $package->setDistType('zip'); - $package->setDistUrl($release->packages->{$this->type->apiName()}); + $package->setDistUrl($distUrl = $release->packages->{$this->type->apiName()}); $package->withRequires($release->php_version); $package->withProvides(); + $package->setDistCallback(function ($pack) use ($distUrl): void { + if ($sha1 = $this->getDistSha1Checksum($distUrl)) { + $pack->setDistSha1Checksum($sha1); + } + }); + return $package; } @@ -44,6 +50,11 @@ public function fetchUnstable(string $endpoint = null): void $this->fetch(($endpoint ?? $this::ENDPOINT) . '?channel=beta'); } + protected function getDistSha1Checksum(string $distUrl): string + { + return trim(file_get_contents($distUrl . '.sha1') ?: ''); + } + public function fetch(string $endpoint = null): self { $this->data = array_merge( diff --git a/tests/ReleaseSources/WPDotOrgAPITest.php b/tests/ReleaseSources/WPDotOrgAPITest.php index 049e6d3b..82cee28c 100644 --- a/tests/ReleaseSources/WPDotOrgAPITest.php +++ b/tests/ReleaseSources/WPDotOrgAPITest.php @@ -20,11 +20,17 @@ public function testGet(): void $this->assertInstanceOf(Repository::class, $repo); $this->assertNotEmpty($repo); + /** @var Package $wpLatest */ $wpLatest = $repo->findPackage($pkgName, '5.8.3'); $this->assertEquals( '5.8.3', $wpLatest->getPrettyVersion() ); + + $this->assertJsonStringEqualsJsonFile( + __DIR__ . '/../resources/source-composer.json', + json_encode($wpLatest, JSON_UNESCAPED_SLASHES) + ); } public function testGetWithUnstable(): void diff --git a/tests/resources/source-composer.json b/tests/resources/source-composer.json new file mode 100644 index 00000000..65206fc2 --- /dev/null +++ b/tests/resources/source-composer.json @@ -0,0 +1,64 @@ +{ + "name": "roots/wordpress-dotorg", + "version": "5.8.3", + "dist": { + "type": "zip", + "url": "https://downloads.wordpress.org/release/wordpress-5.8.3.zip", + "shasum": "27f45019dc89125bf3a87f09c354ae54ea2ea4c9" + }, + "provide": { + "wordpress/core-implementation": "5.8.3" + }, + "require": { + "php": ">= 5.6.20", + "roots/wordpress-core-installer": "^1.0" + }, + "suggest": { + "ext-curl": "Performs remote request operations.", + "ext-dom": "Used to validate Text Widget content and to automatically configuring IIS7+.", + "ext-exif": "Works with metadata stored in images.", + "ext-fileinfo": "Used to detect mimetype of file uploads.", + "ext-hash": "Used for hashing, including passwords and update packages.", + "ext-imagick": "Provides better image quality for media uploads.", + "ext-json": "Used for communications with other servers.", + "ext-libsodium": "Validates Signatures and provides securely random bytes.", + "ext-mbstring": "Used to properly handle UTF8 text.", + "ext-mysqli": "Connects to MySQL for database interactions.", + "ext-openssl": "Permits SSL-based connections to other hosts.", + "ext-pcre": "Increases performance of pattern matching in code searches.", + "ext-xml": "Used for XML parsing, such as from a third-party site.", + "ext-zip": "Used for decompressing Plugins, Themes, and WordPress update packages." + }, + "type": "wordpress-core", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "WordPress Community", + "homepage": "https://wordpress.org/about/" + } + ], + "description": "WordPress is web software you can use to create a beautiful website or blog.", + "homepage": "https://wordpress.org/", + "keywords": [ + "blog", + "cms", + "wordpress" + ], + "support": { + "issues": "https://core.trac.wordpress.org/", + "forum": "https://wordpress.org/support/", + "wiki": "https://codex.wordpress.org/", + "irc": "irc://irc.freenode.net/wordpress", + "source": "https://core.trac.wordpress.org/browser", + "docs": "https://developer.wordpress.org/", + "rss": "https://wordpress.org/news/feed/" + }, + "funding": [ + { + "type": "other", + "url": "https://wordpressfoundation.org/donate/" + } + ] +}