2021-11-11 03:28:10 +00:00
|
|
|
<?php
|
2022-07-06 20:54:48 +00:00
|
|
|
/**
|
|
|
|
* Package_Formatter class
|
|
|
|
*
|
|
|
|
* @package WooCommerce
|
|
|
|
*/
|
2021-11-16 02:01:50 +00:00
|
|
|
|
|
|
|
namespace Automattic\WooCommerce\MonorepoTools\Changelogger;
|
|
|
|
|
|
|
|
use Automattic\Jetpack\Changelogger\FormatterPlugin;
|
|
|
|
|
2021-11-11 03:28:10 +00:00
|
|
|
/**
|
|
|
|
* Jetpack Changelogger Formatter for WooCommerce packages
|
|
|
|
*/
|
|
|
|
|
2022-07-06 20:54:48 +00:00
|
|
|
require_once 'class-formatter.php';
|
2021-11-11 03:28:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Jetpack Changelogger Formatter for WooCommerce Packages
|
|
|
|
*
|
|
|
|
* Class Formatter
|
|
|
|
*/
|
2022-07-06 20:54:48 +00:00
|
|
|
class Package_Formatter extends Formatter implements FormatterPlugin {
|
2021-11-11 03:28:10 +00:00
|
|
|
/**
|
|
|
|
* Prologue text.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $prologue = "# Changelog \n\nThis project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).";
|
|
|
|
|
|
|
|
/**
|
2022-06-29 20:09:46 +00:00
|
|
|
* Return the epilogue string based on the package being released.
|
2021-11-11 03:28:10 +00:00
|
|
|
*/
|
2022-06-29 20:09:46 +00:00
|
|
|
public function getEpilogue() {
|
2022-07-06 20:54:48 +00:00
|
|
|
$cwd = getcwd();
|
|
|
|
$pos = stripos( $cwd, 'packages/js/' );
|
2022-06-29 20:09:46 +00:00
|
|
|
$package = substr( $cwd, $pos + 12 );
|
|
|
|
|
|
|
|
return '[See legacy changelogs for previous versions](https://github.com/woocommerce/woocommerce/blob/68581955106947918d2b17607a01bdfdf22288a9/packages/js/' . $package . '/CHANGELOG.md).';
|
|
|
|
}
|
2022-07-13 03:04:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ) {
|
2023-05-08 07:55:09 +00:00
|
|
|
// Capture anything past /woocommerce in the current working directory.
|
2023-05-04 22:20:11 +00:00
|
|
|
preg_match( '/\/packages\/js\/(.+)/', getcwd(), $path );
|
2022-07-13 03:04:14 +00:00
|
|
|
|
|
|
|
if ( ! count( $path ) ) {
|
|
|
|
throw new \InvalidArgumentException( 'Invalid directory.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'https://www.npmjs.com/package/@woocommerce/' . $path[1] . '/v/' . $version;
|
|
|
|
}
|
2021-11-11 03:28:10 +00:00
|
|
|
}
|