<commit_before><?php


namespace BricksPlatformComposerExtras\Handler;
use Composer\IO\IOInterface;
use Composer\Script\Event;
use BricksPlatformComposerExtras\Processor\ProcessorInterface;

/**
 * Class DeployHandler
 *
 * @package BricksPlatformComposerExtras
 */
class DeployHandler extends AbstractHandler
{
	
	const TARGETS_KEY = 'target';
	const REMOTE_KEY = 'remote';
	
	public function deploy(Event $event) {
		$this->io = $event->getIO();
		
		$arguments = $event->getArguments();
		
		if (!(count($arguments)==1)) {
			throw new \InvalidArgumentException('You have to specify a deployment target as the single argument');
		}
		
		$deployTargetName = $arguments[0];
		
		$this->loadTarget();
		
		$extras = $event->getComposer()->getPackage()->getExtra();
		
		if (!isset($extras[self::EXTRAS_KEY])) {
			throw new \InvalidArgumentException(sprintf('Bricks setup must be configured using the extra.%s setting.', self::EXTRAS_KEY));
		}
		
		$extras = $extras[self::EXTRAS_KEY];
		
		if (!is_array($extras)) {
			throw new \InvalidArgumentException(sprintf('The extra.%s setting must be an array or a configuration object.', self::EXTRAS_KEY));
		}
		
		if (!isset($extras[self::TARGETS_KEY])) {
			$this->getIO()->write('<info>No targets configured, skipping ...</info>');
			return;
		}
		
		$targets = $extras[self::TARGETS_KEY];
		
		if (!isset($extras[self::REMOTE_KEY])) {
			$this->getIO()->write('<info>No remptes configured, skipping ...</info>');
			return;
		}
		
		$remotesConfig = $extras[self::REMOTE_KEY];
		
		$foundTarget=false;
		foreach ($targets as $target) {
			$name=$target['name'];
			if ($name!=$deployTargetName) {
				continue;
			}
			$this->getIO()->write(sprintf('<info>Deploying to target %s</info>',$name));
			$remotes=$target['remote'];
			foreach ($remotes as $remote) {
				// (re)setup remote
				foreach ($remotesConfig as $remoteConfig) {
					if ($remoteConfig['name']==$remote) {
						$color=$remoteConfig['color'];
						$stage=$remoteConfig['stage'];
						$command = sprintf('bricks-deploy setup -r "%s" --color %s --stage %s',$remote,$color,$stage);
						$this->getIO()->write(sprintf('<comment>Executing command %s</comment>',$command));
						shell_exec($command);
					}
				}
				// deploy to remote
				$this->getIO()->write(sprintf('<comment>Deploying to remote %s</comment>',$remote));
				shell_exec(sprintf('git push %s',$remote));
			}
			$foundTarget=true;
			break;
		}
		
		if (!$foundTarget) {
			$this->getIO()->write(sprintf('<error>No target [%s] defined in composer.json</error>',$name));
		}
		
	}

}<commit_msg>setup during deploy only on stage dev<commit_after><?php


namespace BricksPlatformComposerExtras\Handler;
use Composer\IO\IOInterface;
use Composer\Script\Event;
use BricksPlatformComposerExtras\Processor\ProcessorInterface;

/**
 * Class DeployHandler
 *
 * @package BricksPlatformComposerExtras
 */
class DeployHandler extends AbstractHandler
{
	
	const TARGETS_KEY = 'target';
	const REMOTE_KEY = 'remote';
	
	public function deploy(Event $event) {
		$this->io = $event->getIO();
		
		$arguments = $event->getArguments();
		
		if (!(count($arguments)==1)) {
			throw new \InvalidArgumentException('You have to specify a deployment target as the single argument');
		}
		
		$deployTargetName = $arguments[0];
		
		$this->loadTarget();
		
		$extras = $event->getComposer()->getPackage()->getExtra();
		
		if (!isset($extras[self::EXTRAS_KEY])) {
			throw new \InvalidArgumentException(sprintf('Bricks setup must be configured using the extra.%s setting.', self::EXTRAS_KEY));
		}
		
		$extras = $extras[self::EXTRAS_KEY];
		
		if (!is_array($extras)) {
			throw new \InvalidArgumentException(sprintf('The extra.%s setting must be an array or a configuration object.', self::EXTRAS_KEY));
		}
		
		if (!isset($extras[self::TARGETS_KEY])) {
			$this->getIO()->write('<info>No targets configured, skipping ...</info>');
			return;
		}
		
		$targets = $extras[self::TARGETS_KEY];
		
		if (!isset($extras[self::REMOTE_KEY])) {
			$this->getIO()->write('<info>No remptes configured, skipping ...</info>');
			return;
		}
		
		$remotesConfig = $extras[self::REMOTE_KEY];
		
		$foundTarget=false;
		foreach ($targets as $target) {
			$name=$target['name'];
			if ($name!=$deployTargetName) {
				continue;
			}
			$this->getIO()->write(sprintf('<info>Deploying to target %s</info>',$name));
			$remotes=$target['remote'];
			foreach ($remotes as $remote) {
				if (self::getStage()=='dev') {
					// (re)setup remote
					foreach ($remotesConfig as $remoteConfig) {
						if ($remoteConfig['name']==$remote) {
							$color=$remoteConfig['color'];
							$stage=$remoteConfig['stage'];
							$command = sprintf('bricks-deploy setup -r "%s" --color %s --stage %s',$remote,$color,$stage);
							$this->getIO()->write(sprintf('<comment>Executing command %s</comment>',$command));
							shell_exec($command);
						}
					}
				}
				// deploy to remote
				$this->getIO()->write(sprintf('<comment>Deploying to remote %s</comment>',$remote));
				shell_exec(sprintf('git push %s',$remote));
			}
			$foundTarget=true;
			break;
		}
		
		if (!$foundTarget) {
			$this->getIO()->write(sprintf('<error>No target [%s] defined in composer.json</error>',$name));
		}
		
	}

}
{'fraction_non_alphanumeric': 0.1787007048961707, 'fraction_numerical': 0.0007620499142693847, 'mean_word_length': 4.203171456888008, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '750835', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1657, 'n_words': 336}