/**
  * AbstractWorkflowCommand constructor.
  *
  * @param string $origin
  * @param string $stable
  */
 public function __construct(Config $config)
 {
     $this->config = $config;
     $this->origin = $config->get('twgit.git.origin', 'origin');
     $this->stable = $config->get('twgit.git.stable', 'stable');
     $this->prefixes = [self::FEATURE => $config->get('twgit.workflow.prefixes.feature', 'feature-'), self::RELEASE => $config->get('twgit.workflow.prefixes.release', 'release-'), self::HOTFIX => $config->get('twgit.workflow.prefixes.hotfix', 'hotfix-'), self::DEMO => $config->get('twgit.workflow.prefixes.demo', 'demo-'), self::TAG => $config->get('twgit.workflow.prefixes.tag', 'v')];
     $this->firstCommitMessage = $config->get('twgit.commit.first_commit_message', '[twgit] Init %s %s %s');
     $this->featuresSubjectFilename = $config->get('twgit.features.subject_filename', '.twgit_features_subject');
     $this->setConnector(new NullConnector());
 }
 /**
  * @param string $type
  * @param Config $config
  * @param Client $client
  *
  * @return AbstractConnectorCommand
  * @throws ConfigurationException
  */
 public function create($type, Config $config, Client $client)
 {
     $class = sprintf('NMR\\Connector\\%sConnector', ucfirst($type));
     if (!class_exists($class)) {
         throw new ConfigurationException(sprintf('Invalid Connector "%s".', $type));
     }
     $reflectionClass = new ReflectionClass($class);
     $constructorParameters = $reflectionClass->getConstructor()->getParameters();
     $parameters = [];
     /** @var ReflectionParameter $constructorParameter */
     foreach ($constructorParameters as $constructorParameter) {
         $name = $constructorParameter->getName();
         $configName = sprintf('twgit.connectors.%s.%s', $type, TextUtil::convertCamelCaseToSeparator($name));
         $parameters[] = $config->get($configName, '');
     }
     $instance = $reflectionClass->newInstanceArgs($parameters);
     $instance->setClient($client);
     return $instance;
 }
 /**
  * @param $type
  *
  * @return Config
  */
 protected function getConfig()
 {
     if (is_null($this->config)) {
         $this->config = new Config([]);
         foreach (['global', 'type'] as $type) {
             if ('global' === $type) {
                 $file = realpath(__DIR__ . '/../../../app/config/config.yml');
             } else {
                 $file = realpath(getcwd()) . '/.twgit' . '/config.yml';
             }
             if (file_exists($file)) {
                 $yaml = Yaml::parse(file_get_contents($file));
                 $this->config->merge(new Config((new ConfigLoader())->convert($yaml['parameters'], '.', 'twgit')));
             }
         }
     }
     return $this->config;
 }
Exemple #4
0
 /**
  * @param Config $config
  *
  * @return $this
  */
 public function merge(Config $config)
 {
     return $this->override($config->getStorage());
 }
 /**
  * Should manage creation and migration
  * @return bool
  */
 protected function createConfig()
 {
     $this->logger->info('Create config');
     $this->config = Config::create(getenv('HOME'), $this->git->getProjectRootDir());
     foreach (['global', 'project'] as $part) {
         if ('project' === $part && !$this->git->isInGitRepo()) {
             continue;
         }
         $this->initTwgitConfDir($part);
     }
 }
Exemple #6
0
 /**
  * Init configuration object
  */
 protected function initConfig()
 {
     $this->config = Config::create(getenv('HOME'), $this->git->getProjectRootDir());
     $this->config->set('twgit.protected.revision', Application::REVISION);
 }
 /**
  */
 protected function initConfig()
 {
     $createConfigFile = false;
     $this->config = Config::create(getenv('HOME'), realpath(getcwd()));
     $this->config->set('twgit.protected.revision', self::REVISION);
     $sourceConfig = __DIR__ . '/../../app/config/config.yml.dist';
     foreach (['global', 'project'] as $part) {
         $configDir = sprintf($this->config->get(sprintf('twgit.protected.%s.root_dir', $part)));
         $configFile = sprintf('%s/%s', $configDir, $this->config->get('twgit.protected.config_file'));
         if ('project' === $part && !$this->isInGitRepo()) {
             continue;
         }
         if (!is_dir($configDir)) {
             mkdir($configDir, 0755);
         }
         if (!is_file($configFile)) {
             copy($sourceConfig, $configFile);
             $createConfigFile = true;
             $this->logger->help(sprintf('A %s config file has been created in "%s". Please configure it !', $part, $configFile));
         }
         $this->config->import($configFile);
         $sourceConfig = $configFile;
     }
     if ($createConfigFile) {
         exit(1);
     }
 }
 /**
  * Check if twgit is initialized by checking if config exists
  * @throws WorkflowException
  */
 protected function isTwgitInitialized()
 {
     $this->config = Config::create(getenv('HOME'), $this->git->getProjectRootDir());
     $configDir = sprintf($this->config->get(sprintf('twgit.protected.project.config_dir')));
     $configFile = sprintf('%s/%s', $configDir, $this->config->get('twgit.protected.config_file'));
     return file_exists($configFile);
 }