/** * @throws InvalidArgumentException * @param array $argv * @return integer */ public function execute($argv) { $options = pflow_getopt($argv, 'db:np'); // update repo $this->git->fetch('origin'); // create feature branch $branch = $this->getFeatureName($argv); // if we have a local branch, just switch to it if ($this->git->hasBranch($branch)) { $this->output(sprintf('Feature branch "%s" exists, switching to it', $branch)); return $this->git->checkout($branch); } // decide which branch to branch from $baseBranch = $this->getBaseBranch($options, $this->getConfig('pflow.base')); // and switch to it if (false === $this->git->checkout($baseBranch)) { $this->output('Could not checkout to base branch. Commit or stash changes, then run "pflow continue"'); return 0; } // run the steps! $steps = array('updateBaseBranch' => array($options, $baseBranch), 'createFeatureBranch' => array($options, $branch, $baseBranch), 'output' => array(sprintf('Branch (%s) created', $branch)), 'createDatabase' => array($options, $branch), 'showSummary' => array($baseBranch, $branch)); $runner = $this->getStepsRunner($steps); if ($runner->run($this->isContinued() ? $this->getConfig('pflow.continue') : null)) { $this->outputSuccessfulStart($argv, $baseBranch); return 1; } return 0; }
/** * @param string $argv * @return int */ public function execute($argv) { $options = pflow_getopt($argv, 'ds:'); // uninstall if (isset($options['d'])) { return $this->executeUninstall(); } if (isset($options['s'])) { if (!in_array($options['s'], $this->sections)) { throw new InvalidArgumentException(sprintf("Invalid section option. Only the following values are accepted: %s", implode(',', $this->sections))); } $sectionsToConfigure = array($options['s']); } else { $sectionsToConfigure = $this->sections; } $this->output('PMSIpilot flow configuration'); if (in_array('crew', $sectionsToConfigure)) { $this->configureCrew(); } if (in_array('base-branch', $sectionsToConfigure)) { $this->configureBaseBranch(); } if (in_array('database', $sectionsToConfigure)) { $this->configureDatabase(); } if (in_array('jabber', $sectionsToConfigure)) { $this->configureJabber(); } $this->git->setConfig('pflow.installed', 1); $this->output('thank you, pflow is now configured!'); return 1; }
/** * pflow feature finish * * @param array $argv * @return integer */ public function execute($argv) { $options = pflow_getopt($argv, 'pd'); if ($this->isContinued()) { $featureBranch = $this->getConfig('pflow.finish-feature'); if (false === $this->git->checkout($featureBranch)) { $this->output(sprintf('Could not checkout to feature branch %s.', $featureBranch)); return 0; } } else { $featureBranch = $this->git->getCurrentBranch(); $this->git->setConfig('pflow.finish-feature', $featureBranch); } try { $baseBranch = $this->getConfig(sprintf('branch.%s.base', $featureBranch)); } catch (InvalidArgumentException $e) { $this->output(sprintf('Unable to find base branch configuration for feature branch %s.', $featureBranch)); return 0; } $steps = array('updateBaseBranch' => array($baseBranch), 'tryMergeFeatureBranch' => array($featureBranch, $baseBranch), 'pushFeatureBranch' => array($options, $baseBranch), 'dropDatabase' => array($options, $featureBranch)); $runner = $this->getStepsRunner($steps); if ($runner->run($this->isContinued() ? $this->getConfig('pflow.continue') : null)) { $this->git->removeConfig('pflow.finish-feature'); $this->output(sprintf('Finished working on feature %s (merged in %s)', $featureBranch, $baseBranch), Output::SCOPE_PUBLIC); return 1; } return 0; }
<?php require_once dirname(__FILE__) . '/../lib/pmsipilot-flow/pflow_getopt.php'; $tests = array(array('db:np', 'feature start 42 -b 7.4 -p', array('b' => '7.4', 'p' => true)), array('db:np', 'feature start 42 - 7.4 -p', array('p' => true)), array('h:v:', 'hudson show -h http://localhost:8080/', array('h' => 'http://localhost:8080/'))); $fails = 0; foreach ($tests as $i => $test) { list($def, $argv, $expect) = $test; $argv = explode(' ', $argv); $got = pflow_getopt($argv, $def); if ($got !== $expect) { $fails++; echo sprintf('>> failed test #%d (%s) (got: %s, expected: %s', $i, $def, var_export($got, true), var_export($expect, true)) . PHP_EOL; } } if ($fails > 0) { echo 'Failed ' . $fails . ' tests'; } else { echo 'All clear!'; } echo PHP_EOL;
#!/usr/bin/env php <?php //--------------- // Default values //--------------- date_default_timezone_set('America/New_York'); $version = '0.1'; $gitDir = $_SERVER["PWD"]; $iteration = 15; $nbCommits = 10; $displayNoMergedBranches = true; $displayStats = true; //-------- // Options //-------- $options = pflow_getopt($argv, 'd:i:c:h:v:no-stat:no-merged-branch'); if (isset($options['h'])) { usage(); exit; } if (isset($options['v'])) { printf("%s\n", $version); exit; } if (isset($options['d']) && $options['d'] !== false) { $gitDir = $options['d']; } if (isset($options['i']) && $options['i'] !== false && is_numeric($options['i'])) { $iteration = $options['i']; } if (isset($options['c']) && $options['c'] !== false && is_numeric($options['c'])) {