Skip to content

Commit

Permalink
API Add --push option and fix git control
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Aug 20, 2015
1 parent e811853 commit 428869b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ Outside of doing core releases, you can use this for specific modules

* `module:translate <modules>` Updates translations for modules and commits this to source control. If you
don't specify a list of modules then all modules will be translated. Specify 'installer' for root module.
You can use `--push` option to push to origin at the end, or `--exclude` if your list of modules is the list
to exclude. By default all modules are included, unless whitelisted or excluded.

7 changes: 6 additions & 1 deletion src/Commands/Module/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected function configure() {
);
$this->addOption('directory', 'd', InputOption::VALUE_REQUIRED, 'Module directory');
$this->addOption('exclude', 'e', InputOption::VALUE_NONE, "Makes list of modules exclusive instead of inclusive");
$this->addOption('push', 'p', InputOption::VALUE_NONE, "Push to git origin if successful");
}

/**
Expand Down Expand Up @@ -52,6 +53,10 @@ protected function getInputModules() {
* @return bool
*/
protected function getInputExclude() {
return $this->input->getOption('exclude');
return (bool)$this->input->getOption('exclude');
}

protected function getInputPush() {
return (bool)$this->input->getOption('push');
}
}
3 changes: 2 additions & 1 deletion src/Commands/Module/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ protected function fire() {
$directory = $this->getInputDirectory();
$modules = $this->getInputModules();
$listIsExclusive = $this->getInputExclude();
$push = $this->getInputPush();

$translate = new UpdateTranslations($this, $directory, $modules, $listIsExclusive);
$translate = new UpdateTranslations($this, $directory, $modules, $listIsExclusive, $push);
$translate->run($this->input, $this->output);
//$step->run($this->input, $this->output);
}
Expand Down
30 changes: 26 additions & 4 deletions src/Steps/Release/UpdateTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,29 @@ class UpdateTranslations extends Step {
*/
protected $listIsExclusive;

/**
* Flag whether we should do push on each git repo
*
* @var bool
*/
protected $push;

/**
* Create a new translation step
*
* @param Command $command
* @param string $directory Where to translate
* @param array $modules Optional list of modules to limit translation to
* @param bool $listIsExclusive If this list is exclusive. If false, this is inclusive
* @param bool $push Do git push at end
*/
public function __construct(Command $command, $directory, $modules = array(), $listIsExclusive = false) {
public function __construct(Command $command, $directory, $modules = array(), $listIsExclusive = false, $doPush = false) {
parent::__construct($command);

$this->modules = $modules;
$this->listIsExclusive = $listIsExclusive;
$this->project = new Project($directory);
$this->push = $doPush;
}

/**
Expand Down Expand Up @@ -276,10 +285,23 @@ public function commitChanges(OutputInterface $output, $modules) {
$jsPath = $module->getJSLangDirectory();
$langPath = $module->getLangDirectory();
foreach(array_merge((array)$jsPath, (array)$langPath) as $path) {
$repo->run("add", array($path . "/*"));
if(is_dir($path)) {
$repo->run("add", array($path . "/*"));
}
}

// Commit changes if any exist
$status = $repo->run("status");
if(stripos($status, 'Changes to be committed:')) {
$this->log($output, "Comitting changes for module " . $module->getName());
$repo->run("commit", array("-m", "Update translations"));
}

// Do push if selected
if($this->push) {
$this->log($output, "Pushing upstream for module " . $module->getName());
$repo->run("push", array("origin"));
}

$repo->run("commit", array("-m", "Update translations"));
}
}

Expand Down

0 comments on commit 428869b

Please sign in to comment.