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) {
|
||||
require_once __DIR__ . '/tasks/GithubClient.php';
|
||||
$help = "Use your GitHub username and a token from https://github.com/settings/tokens with 'repo' scopes.";
|
||||
$githubClient = new \MailPoetTasks\GithubClient(
|
||||
$this->getEnv('WP_GITHUB_USERNAME', $help),
|
||||
$this->getEnv('WP_GITHUB_TOKEN', $help),
|
||||
'woocommerce/woocommerce-subscriptions'
|
||||
);
|
||||
$githubClient->downloadReleaseZip('woocommerce-subscriptions.zip', __DIR__ . '/tools/vendor/', $tag);
|
||||
if (!getenv('WP_GITHUB_USERNAME') && !getenv('WP_GITHUB_TOKEN')) {
|
||||
$this->yell("Skipping download of WooCommerce Subscriptions", 40, 'red');
|
||||
exit(0); // Exit with 0 since it is a valid state for some environments
|
||||
}
|
||||
$this->createGithubClient('woocommerce/woocommerce-subscriptions')
|
||||
->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) {
|
||||
@@ -1022,6 +1025,15 @@ class RoboFile extends \Robo\Tasks {
|
||||
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() {
|
||||
define('ABSPATH', getenv('WP_ROOT') . '/');
|
||||
if (\MailPoet\Config\Env::$dbPrefix === null) {
|
||||
|
@@ -10,14 +10,17 @@ class GithubClient {
|
||||
|
||||
private const API_BASE_URI = 'https://api.github.com/repos';
|
||||
|
||||
public function __construct($username, $token, $repo) {
|
||||
$this->httpClient = new Client([
|
||||
'auth' => [$username, $token],
|
||||
public function __construct($repo, $username = null, $token = null) {
|
||||
$config = [
|
||||
'headers' => [
|
||||
'Accept' => 'application/vnd.github.v3+json',
|
||||
],
|
||||
'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) {
|
||||
|
Reference in New Issue
Block a user