Skip to content

Commit

Permalink
Merge pull request #25 from matiere-noire/clone-commands
Browse files Browse the repository at this point in the history
Refactor et github autocomplete
  • Loading branch information
Arnaud Banvillet authored Feb 28, 2020
2 parents 34e3aa5 + a6b246b commit 9d4ad39
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 36 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"require": {
"consolidation/robo": "^2.0",
"symfony/yaml": "4"
"symfony/yaml": "4",
"ext-json": "*"
},
"require-dev": {
"roave/security-advisories": "dev-master"
Expand Down
9 changes: 7 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<?php

// If we're running from phar load the phar autoload file.
use Consolidation\AnnotatedCommand\CommandFileDiscovery;

$pharPath = \Phar::running(true);
if ($pharPath) {
$autoloaderPath = "$pharPath/vendor/autoload.php";
Expand All @@ -19,8 +21,11 @@
// Customization variables
$appName = 'Roger';
//$appVersion = trim(file_get_contents(__DIR__ . '/VERSION'));
$appVersion = '1.1';
$commandClasses = [ \Roger\Commands\RoboFile::class ];
$appVersion = '1.2';
$discovery = new CommandFileDiscovery();
$discovery->setSearchPattern('*Commands.php');
$commandClasses = $discovery->discover('src/Commands', '\Roger\Commands');

$selfUpdateRepository = 'matiere-noire/roger';
$configurationFilename = "{$_SERVER['HOME']}/.roger/robo.yml";

Expand Down
70 changes: 70 additions & 0 deletions src/Commands/CleverCloudCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php


namespace Roger\Commands;


use Robo\Exception\TaskException;
use Robo\Tasks;
use Roger\Services\GithubServices;
use Symfony\Component\Console\Question\Question;

class CleverCloudCommands extends Tasks
{

private $ccOrganisation;

public function __construct()
{
$this->ccOrganisation = 'orga_36652de4-73cd-4058-8f16-7ec47d8d2816';
}

/**
* Création d'un projet Clever Cloud avec une addon MySQL et FS Bucket
*
* @param string|null $githubName Nom du projet Github
* @param array $opt
* @option $localProject Emplacement du depot local auquel sera ajouter le .clever.json
* @option $ccName Nom du nouveau projet Clever Cloud
*
* @throws TaskException
*/
public function createCC( $githubName = null, $opt = [ 'localProject|d' => null, 'ccName' => null ] ): void
{

if( ! $githubName ){
$result = $this
->taskExec('hub api -X GET /search/repositories?q=user:matiere-noire+topic:project')
->printOutput(false)
->printMetadata( false )
->run();
$data = json_decode( $result->getMessage(), false);

$prjectsNames = array_map( static function ($item) {
return $item->name;
}, $data->items );

$question = new Question('Nom de votre projet sur Github ');
$question->setAutocompleterValues( $prjectsNames );

$githubName = $this->doAsk( $question );
}


$localProject = $opt['localProject'] ?? $this->ask('path du projet en local ?');
$ccName = $opt['ccName'] ?? $this->askDefault('Nom du nouveau projet Clever Cloud ?', "{$githubName}-WP");

$ccTask = $this->taskExecStack()
->stopOnFail( true )
->exec("clever create --type php {$ccName} --org {$this->ccOrganisation} --github matiere-noire/{$githubName} --alias {$githubName}" )
->exec('clever scale --flavor nano')
->exec("clever addon create mysql-addon --plan dev {$githubName}-MySQL --link {$githubName} --org {$this->ccOrganisation}")
->exec("clever addon create fs-bucket --plan s {$githubName}-fs --link {$githubName} --org {$this->ccOrganisation}");

if( $localProject ){
$ccTask->dir( $localProject );
}

$ccTask->run();
}
}
41 changes: 41 additions & 0 deletions src/Commands/GithubCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php


namespace Roger\Commands;


use Robo\Tasks;
use Symfony\Component\Console\Question\Question;

class GithubCommands extends Tasks
{


private $githubOrganisation;

public function __construct()
{
$this->githubOrganisation = 'matiere-noire';
}


/**
* Créer un projet Github privé avec le nom demandé
*
* @param string|null $projectName Nom de projet Github a créer
* @param array $opt
* @option $localDepot Emplacement du depot local auquel le projet github sera ajouté comme git remote
*/
public function createGithub( $projectName = null, $opt = [ 'localDepot|d' => null ]): void
{
if( ! $projectName ){
$projectName = $this->ask( 'Nom de votre nouveau projet sur Github ? ');
}

$creatTask = $this->taskExec( "hub create {$this->githubOrganisation}/{$projectName} -o -p" );
if( $opt['localDepot'] ){
$creatTask->dir( $opt['localDepot'] );
}
$creatTask->run();
}
}
36 changes: 3 additions & 33 deletions src/Commands/RoboFile.php → src/Commands/ProjectCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @see http://robo.li/
*/
class RoboFile extends Tasks
class ProjectCommands extends Tasks
{

private $projectName;
Expand Down Expand Up @@ -223,7 +223,7 @@ public function createWP( $opt = [

// github
if( $createGithub ){
$this->taskExec( "hub create matiere-noire/{$this->projectName} -o -p" )->dir( $this->projectDir )->run();
$this->_exec("roger create:github {$this->projectName} -d $this->projectDir");

$this->taskGitStack()
->push('origin','master')
Expand All @@ -233,7 +233,7 @@ public function createWP( $opt = [

if( $createCleverCloudApp ){

$this->createCC();
$this->_exec( "roger create:cc {$this->projectName} -d $this->projectDir --ccName {$this->projectName}-WP");
}


Expand Down Expand Up @@ -317,36 +317,6 @@ private function addPlugins(){
}


/**
* Création d'un projet Clever Cloud avec une addon MySQL et FS Bucket
*
* @throws TaskException
*/
public function createCC()
{

if( ! $this->projectName ){
$this->projectName = $this->askDefault('Nom du nouveau projet ?', 'super');
}
if( ! $this->projectDir ){
$this->projectDir = $this->ask('path du projet en local ?');
}

$ccTask = $this->taskExecStack()
->stopOnFail( true )
->exec("clever create --type php {$this->projectName}-WP --org orga_36652de4-73cd-4058-8f16-7ec47d8d2816 --github matiere-noire/{$this->projectName} --alias {$this->projectName}" )
->exec('clever scale --flavor nano')
->exec("clever addon create mysql-addon --plan dev {$this->projectName}-MySQL --link {$this->projectName} --org orga_36652de4-73cd-4058-8f16-7ec47d8d2816")
->exec("clever addon create fs-bucket --plan s {$this->projectName}-fs --link {$this->projectName} --org orga_36652de4-73cd-4058-8f16-7ec47d8d2816");

if( $this->projectDir ){
$ccTask->dir( $this->projectDir );
}

$ccTask->run();

}


/**
* Configurer l'assistant
Expand Down

0 comments on commit 9d4ad39

Please sign in to comment.