コード例 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $api = $this->getContainer()->get('git_automation.jira_api');
     $permanentBranches = ['dev', 'master', 'facebook'];
     $branches = $this->git->branches();
     $branches = array_filter(array_map(function ($val) use($permanentBranches) {
         $val = trim($val);
         if (in_array($val, $permanentBranches)) {
             return false;
         }
         $val = preg_replace("/_.*/i", "", $val);
         if (strpos($val, '-') > 1 && strpos($val, '-') < strlen($val) - 1) {
             return $val;
         }
         return false;
     }, $branches));
     $walker = new Walker($api);
     $query = 'key IN ("' . implode('","', $branches) . '")';
     $walker->push($query);
     /** @var \chobie\Jira\Issue $issue */
     $deleted = [];
     foreach ($walker as $issue) {
         $closedStatuses = ["approved", "awaiting for check", "closed (won't fix)", "closed success"];
         if (in_array(strtolower($issue->getStatus()['name']), $closedStatuses)) {
             $output->writeln($issue->getKey() . ' is closed ');
             $this->git->branchDelete($issue->getKey(), true);
             $deleted[] = $issue->getKey();
         } else {
             $output->writeln($issue->getKey() . ' is ' . $issue->getStatus()['name']);
         }
     }
     if (!empty($deleted)) {
         $this->git->deleteRemoteBranches($deleted);
     }
 }
コード例 #2
0
 public function testPublicReadonlyNew()
 {
     $source = "https://github.com/shadiakiki1986/ffa-gdr-public";
     $path = tempnam("/tmp", "test");
     unlink($path);
     $gr = \Coyl\Git\GitRepo::create($path, $source);
     $gdr = new GitDataRepo($gr, $source);
     $hml = $gdr->get("sic_countries_hml.json");
     $this->assertNotNull($hml);
 }
コード例 #3
0
 /**
  * repoPath: data repo path since using git-data-repo
  *           e.g. /var/cache/ffamfe_tcm
  * authFn: e.g. __DIR__."/../auth.json", false for no credentials, e.g. read-only usage of public repo
  * remote, e.g. https://bitbucket.org/shadiakiki1986/ffa-bdlreports-maps
  * loglevel=\Monolog\Logger::WARNING; // isset($argc)?\Monolog\Logger::DEBUG:\Monolog\Logger::WARNING;
  * gitconfig: e.g. array('user.email'=>'*****@*****.**','user.name'=>'my name')
  *
  * @SuppressWarnings(PHPMD.StaticAccess)
  */
 public static function initGdrPersistentFromAuthJson($repoPath, $authFn, $remoteUrl, $loglevel = \Monolog\Logger::WARNING, $gitconfig = array())
 {
     // copied from accounting-bdlreports-mapeditor/action.php
     // check can put files here
     if (!is_writable($repoPath)) {
         throw new \Exception("Cache folder '" . $repoPath . "' is not writable. You may need `[sudo] chown www-data:www-data -R " . $repoPath . "`");
     }
     // get remote credentials
     $remote = null;
     if ($authFn) {
         if (!file_exists($authFn)) {
             throw new \Exception("File not found '" . $authFn . "'");
         }
         $remote = json_decode(file_get_contents($authFn), true);
         $remote = $remote["http-basic"]["bitbucket.org"];
         $remote = GitDataRepo::injectRemoteCredentials($remoteUrl, $remote["username"], $remote["password"]);
     } else {
         $remote = $remoteUrl;
     }
     # copied from https://github.com/coyl/git/blob/master/src/Coyl/Git/GitRepo.php#L43
     $isgit = is_dir($repoPath) && file_exists($repoPath . "/.git") && is_dir($repoPath . "/.git");
     if ($isgit) {
         $gitRepo = new \Coyl\Git\GitRepo($repoPath, false, false);
         return new \GitDataRepo\GitDataRepo($gitRepo, $remote, $loglevel);
     }
     # case of new git repo
     $gitRepo = \Coyl\Git\GitRepo::create($repoPath, $remote);
     # run some git config if needed
     foreach ($gitconfig as $k => $v) {
         $cmd = "config " . $k . " '" . $v . "'";
         $gitRepo->run($cmd);
     }
     return new \GitDataRepo\GitDataRepo($gitRepo, $remote, $loglevel);
 }