JS Package Release: Fix NPM link (#33800)

This commit is contained in:
Paul Sealock 2022-07-13 15:04:14 +12:00 committed by GitHub
parent a0a242f6a7
commit 62b91768fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 21 deletions

View File

@ -84,27 +84,7 @@ class Formatter extends KeepAChangelogParser {
* @return string Link to the version's release.
*/
public function getReleaseLink( $version ) {
// Catpure anything past /woocommerce in the current working directory.
preg_match( '/\/woocommerce\/(.+)/', getcwd(), $path );
if ( ! count( $path ) ) {
throw new \InvalidArgumentException( 'Invalid directory.' );
}
$release_url = '';
if ( strpos( $path[1], 'packages/js/' ) !== false ) {
$package = substr( $path[1], 12 );
$release_url = 'https://www.npmjs.com/package/@woocommerce/' . $package . '/v/';
} elseif ( 'plugins/woocommerce' === $path[1] ) {
$release_url = 'https://github.com/woocommerce/woocommerce/releases/tag/';
} elseif ( 'plugins/woocommerce-beta-tester' === $path[1] ) {
$release_url = 'https://github.com/woocommerce/woocommerce/releases/tag/';
} else {
throw new \InvalidArgumentException( 'Release URL not found.' );
}
return $release_url . $version;
return 'https://github.com/woocommerce/woocommerce/releases/tag/' . $version;
}
/**

View File

@ -38,4 +38,23 @@ class Package_Formatter extends Formatter implements FormatterPlugin {
return '[See legacy changelogs for previous versions](https://github.com/woocommerce/woocommerce/blob/68581955106947918d2b17607a01bdfdf22288a9/packages/js/' . $package . '/CHANGELOG.md).';
}
/**
* Get Release link given a version number.
*
* @throws \InvalidArgumentException When directory parsing fails.
* @param string $version Release version.
*
* @return string Link to the version's release.
*/
public function getReleaseLink( $version ) {
// Catpure anything past /woocommerce in the current working directory.
preg_match( '/\/woocommerce\/packages\/js\/(.+)/', getcwd(), $path );
if ( ! count( $path ) ) {
throw new \InvalidArgumentException( 'Invalid directory.' );
}
return 'https://www.npmjs.com/package/@woocommerce/' . $path[1] . '/v/' . $version;
}
}