/**
  * runs a command from the root dir or the module
  */
 protected function runCommand()
 {
     if ($this->command != null) {
         GeneralMethods::outputToScreen('Running ' . $this->command);
         return exec(' cd ' . $this->rootDirForModule . ';
             ' . $this->command . '
             ');
     }
 }
 public function updateJsonData()
 {
     if (!isset($this->jsonData)) {
         $this->readJsonFromFile();
     }
     if (isset($this->jsonData)) {
         GeneralMethods::outputToScreen("<li> Updating composer.json </li>");
         $composerUpdates = ClassInfo::subclassesFor('UpdateComposer');
         array_shift($composerUpdates);
         $limitedComposerUpdates = $this->Config()->get('updates');
         if ($limitedComposerUpdates && count($limitedComposerUpdates)) {
             $composerUpdates = array_intersect($composerUpdates, $limitedComposerUpdates);
         }
         foreach ($composerUpdates as $composerUpdate) {
             $obj = $composerUpdate::create($this);
             $obj->run();
         }
         $this->writeJsonToFile();
     } else {
         GeneralMethods::outputToScreen('<li style = "color: red;"> ' . $this->moduleName . '  has no composer.json !!!</li>');
     }
 }
 public function addRepoToScrutinzer()
 {
     if (!trim($this->Config()->get('scrutinizer_api_key'))) {
         GeneralMethods::outputToScreen("<li> not Scrutinizer API key set </li>");
         return false;
     }
     //see https://scrutinizer-ci.com/docs/api/#repositories
     $scrutinizerApiPath = "https://scrutinizer-ci.com/api";
     $endPoint = "repositories/g?access_token=" . trim($this->Config()->get('scrutinizer_api_key'));
     $url = $scrutinizerApiPath . "/" . $endPoint;
     $username = $this->Config()->get('git_user_name');
     $repoName = $username . '/' . $this->ModuleName;
     $postFields = array('name' => $repoName);
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields));
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, count($postFields));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $curlResult = curl_exec($ch);
     if (!$curlResult) {
         die('Curl failed.');
     }
     $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($httpcode == 201) {
         GeneralMethods::outputToScreen("<li> Added {$repoName} to Scrutinizer ... </li>");
     } else {
         GeneralMethods::outputToScreen("<li> could not add {$repoName} to Scrutinizer ... </li>");
     }
     /* print_r($repoName);
             print_r($url);
             print_r('<br/>');
             print_r($curlResult );
     
     
     
     
             die();*/
 }
 protected function existsOnAddOns($name)
 {
     return GeneralMethods::check_location("http://addons.silverstripe.org/add-ons/" . $this->Config()->get("packagist_user_name") . "/{$name}");
 }
 private function checkUpdateTag($moduleObject)
 {
     $aWeekAgo = strtotime("-1 weeks");
     $tag = $moduleObject->getLatestTag();
     $commitTime = $moduleObject->getLatestCommitTime();
     $createTag = false;
     if (!$tag) {
         $createTag = true;
         $newTagString = '1.0.0';
     } else {
         if ($tag && $commitTime > $tag['timestamp'] && $commitTime < $aWeekAgo) {
             $createTag = true;
             $tag['tagparts'][1] = $tag['tagparts'][1] + 1;
             $newTagString = trim(implode('.', $tag['tagparts']));
         }
     }
     if ($createTag) {
         GeneralMethods::outputToScreen('<li> Creating new tag  ' . $newTagString . ' ... </li>');
         //git tag -a 0.0.1 -m "testing tag"
         $options = array('a' => $newTagString, 'm' => $this->Config()->get('tag_create_message'));
         $moduleObject->createTag($options);
     }
 }
 /**
  * @param string $file
  * @param GitHubModule $gitObject
  *
  * @return string
  */
 public function replaceWordsInFile()
 {
     foreach ($this->gitReplaceArray as $searchTerm => $replaceMethod) {
         $fileName = $this->rootDirForModule . '/' . $this->fileLocation;
         GeneralMethods::replaceInFile($fileName, $searchTerm, $this->gitObject->{$replaceMethod}());
     }
     foreach ($this->replaceArray as $searchTerm => $replaceMethod) {
         $fileName = $this->rootDirForModule . '/' . $this->fileLocation;
         GeneralMethods::replaceInFile($fileName, $searchTerm, $this->{$replaceMethod}());
     }
 }