Skip to content

Commit

Permalink
Add shasum value into generated packages
Browse files Browse the repository at this point in the history
Close #1
  • Loading branch information
LeoColomb committed Feb 14, 2022
1 parent 22f02ab commit abd2054
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ReleaseSources/WPDotOrgAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions tests/ReleaseSources/WPDotOrgAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions tests/resources/source-composer.json
Original file line number Diff line number Diff line change
@@ -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/"
}
]
}

0 comments on commit abd2054

Please sign in to comment.