Add robo command for downloading WooCommerce
[MAILPOET-3482]
This commit is contained in:
committed by
Veljko V
parent
17c0e26b02
commit
ff806859cb
28
RoboFile.php
28
RoboFile.php
@@ -898,14 +898,17 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function downloadWooCommerceSubscriptionsZip($tag = null) {
|
public function downloadWooCommerceSubscriptionsZip($tag = null) {
|
||||||
require_once __DIR__ . '/tasks/GithubClient.php';
|
if (!getenv('WP_GITHUB_USERNAME') && !getenv('WP_GITHUB_TOKEN')) {
|
||||||
$help = "Use your GitHub username and a token from https://github.com/settings/tokens with 'repo' scopes.";
|
$this->yell("Skipping download of WooCommerce Subscriptions", 40, 'red');
|
||||||
$githubClient = new \MailPoetTasks\GithubClient(
|
exit(0); // Exit with 0 since it is a valid state for some environments
|
||||||
$this->getEnv('WP_GITHUB_USERNAME', $help),
|
}
|
||||||
$this->getEnv('WP_GITHUB_TOKEN', $help),
|
$this->createGithubClient('woocommerce/woocommerce-subscriptions')
|
||||||
'woocommerce/woocommerce-subscriptions'
|
->downloadReleaseZip('woocommerce-subscriptions.zip', __DIR__ . '/tools/vendor/', $tag);
|
||||||
);
|
}
|
||||||
$githubClient->downloadReleaseZip('woocommerce-subscriptions.zip', __DIR__ . '/tools/vendor/', $tag);
|
|
||||||
|
public function downloadWooCommerceZip($tag = null) {
|
||||||
|
$this->createGithubClient('woocommerce/woocommerce')
|
||||||
|
->downloadReleaseZip('woocommerce.zip', __DIR__ . '/tools/vendor/', $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateData($generatorName = null) {
|
public function generateData($generatorName = null) {
|
||||||
@@ -1022,6 +1025,15 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
return $exitCode;
|
return $exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createGithubClient($repositoryName) {
|
||||||
|
require_once __DIR__ . '/tasks/GithubClient.php';
|
||||||
|
return new \MailPoetTasks\GithubClient(
|
||||||
|
$repositoryName,
|
||||||
|
getenv('WP_GITHUB_USERNAME') ?: null,
|
||||||
|
getenv('WP_GITHUB_TOKEN') ?: null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private function createDoctrineEntityManager() {
|
private function createDoctrineEntityManager() {
|
||||||
define('ABSPATH', getenv('WP_ROOT') . '/');
|
define('ABSPATH', getenv('WP_ROOT') . '/');
|
||||||
if (\MailPoet\Config\Env::$dbPrefix === null) {
|
if (\MailPoet\Config\Env::$dbPrefix === null) {
|
||||||
|
@@ -10,14 +10,17 @@ class GithubClient {
|
|||||||
|
|
||||||
private const API_BASE_URI = 'https://api.github.com/repos';
|
private const API_BASE_URI = 'https://api.github.com/repos';
|
||||||
|
|
||||||
public function __construct($username, $token, $repo) {
|
public function __construct($repo, $username = null, $token = null) {
|
||||||
$this->httpClient = new Client([
|
$config = [
|
||||||
'auth' => [$username, $token],
|
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Accept' => 'application/vnd.github.v3+json',
|
'Accept' => 'application/vnd.github.v3+json',
|
||||||
],
|
],
|
||||||
'base_uri' => self::API_BASE_URI . "/$repo/",
|
'base_uri' => self::API_BASE_URI . "/$repo/",
|
||||||
]);
|
];
|
||||||
|
if ($username && $token) {
|
||||||
|
$config['auth'] = [$username, $token];
|
||||||
|
}
|
||||||
|
$this->httpClient = new Client($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downloadReleaseZip($zip, $downloadDir, $tag = null) {
|
public function downloadReleaseZip($zip, $downloadDir, $tag = null) {
|
||||||
|
Reference in New Issue
Block a user