-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from matiere-noire/clone-commands
Refactor et github autocomplete
- Loading branch information
Showing
5 changed files
with
123 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters