diff --git a/tools/changelogger/class-formatter.php b/tools/changelogger/class-formatter.php index a74816fefa7..5b9d0f86a39 100644 --- a/tools/changelogger/class-formatter.php +++ b/tools/changelogger/class-formatter.php @@ -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; } /** diff --git a/tools/changelogger/class-package-formatter.php b/tools/changelogger/class-package-formatter.php index 3e2e8938b89..d4d10ddcd97 100644 --- a/tools/changelogger/class-package-formatter.php +++ b/tools/changelogger/class-package-formatter.php @@ -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; + } }