예제 #1
0
 /**
  * @param $argument
  * @param $option
  */
 private function hardWork($argument, $option)
 {
     $command = $this;
     $this->workbenchSettings = new WorkbenchSettings($command);
     $this->workbenchSettings->prepare($this->input->getOption("user"), "user");
     $this->workbenchSettings->prepare($this->input->getOption("password"), "password");
     $this->workbenchSettings->prepare($this->input->getOption("email"), "email");
     $this->workbenchSettings->prepare($this->domain, "domain");
     $this->workbenchSettings->prepare("public", "dirtype");
     $this->workbenchSettings->prepare($this->ORGANIZATION_PATH, "dir");
     $this->workbenchSettings->prepare("github", "git");
     $this->workbenchSettings->prepare($this->organization, "organization");
     $this->workbenchSettings->prepare($this->packagename, "packagename");
     $user = new Parameters\User($command);
     $user->read(false);
     $password = new Parameters\Password($command);
     $password->read(false);
     $email = new Parameters\Email($command);
     $email->read(false);
     $apiSamiGeneration = new WorkbenchApiGeneration($this->workbenchSettings, $this);
     $apiSamiGeneration->apiSamiGeneration();
 }
예제 #2
0
 /**
  * @param $argument
  * @param $option
  */
 private function hardWork($argument, $option)
 {
     $command = $this;
     $this->workbenchSettings = new WorkbenchSettings($command);
     //$this->workbenchSettings->prepare("github","git");
     $this->workbenchSettings->prepare($this->input->getOption("user"), "user");
     $this->workbenchSettings->prepare($this->input->getOption("password"), "password");
     $this->workbenchSettings->prepare($this->input->getOption("email"), "email");
     $this->workbenchSettings->prepare($this->domain, "domain");
     $this->workbenchSettings->prepare("public", "dirtype");
     $this->workbenchSettings->prepare($this->ORGANIZATION_PATH, "dir");
     $this->workbenchSettings->prepare("github", "git");
     $this->workbenchSettings->prepare($this->organization, "organization");
     $this->workbenchSettings->prepare($this->packagename, "packagename");
     $user = new Parameters\User($command);
     $user->read(false);
     $password = new Parameters\Password($command);
     $password->read(false);
     $email = new Parameters\Email($command);
     $email->read(false);
     //$gitWrapper = new GitWrapper();
     //$gitWorkingCopy = $gitWrapper->workingCopy($this->BASE_PATH);
     $gitSimpleWrapper = new GitSimpleWrapper($this->BASE_PATH, null);
     $gitSimpleWrapper->git("remote update");
     //$gitWorkingCopy->remote("update");
     //$commitControl = $gitWorkingCopy->status("-uno");
     $commitControl = "";
     try {
         $output = $gitSimpleWrapper->git("status -uno");
         is_array($output) ? $commitControl = implode("\r\n", $output) : ($commitControl = $output);
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
     $this->info($commitControl);
     preg_match("(Your branch is ahead|Your branch is up-to-date|Changes not staged for commit|nothing to commit)", $commitControl, $matches);
     if (count($matches) == 0) {
         echo "The local commit isn't update with remote commit";
         exit;
     }
     $this->info($matches[0]);
     $activebranch = $this->getActiveBranch($gitSimpleWrapper);
     //$message="Test package";
     $message = "DEBUG";
     if (!$this->DEBUG) {
         do {
             $message = $this->ask("Commit message");
         } while ($message == "");
     }
     $this->info("Active branch is " . $activebranch);
     $gitSimpleWrapper->git("add .");
     $this->addAndCommit($gitSimpleWrapper, $message);
     $lastTag = $this->getLastTagVersion($gitSimpleWrapper);
     $this->line("Last tag version is " . $lastTag);
     $tagVersionOriginal[0] = 0;
     $tagVersionOriginal[1] = 0;
     $tagVersionOriginal[2] = 0;
     $tagVersion[0] = 0;
     $tagVersion[1] = 0;
     $tagVersion[2] = 1;
     if ($lastTag != "0.0.0") {
         $tagVersion = $this->getLastTagVersionArray($gitSimpleWrapper);
         $this->createSemverCopyFolder($gitSimpleWrapper);
         //$output = array();
         $output = $this->runSemVer();
         $this->line(implode("\r\n", $output));
         $this->warn("Semver output will be saved in " . sys_get_temp_dir() . "/semver_output" . date("Y-m-d") . ".txt");
         file_put_contents(sys_get_temp_dir() . "/semver_output" . date("Y-m-d") . ".txt", implode("\r\n", $output));
         $semVerVersion = $this->semVerAnalisys($output);
         $this->info("Suggested semantic versioning change: " . $semVerVersion);
         $color = "";
         $tagVersionOriginal = $tagVersion;
         switch ($semVerVersion) {
             case "MAJOR":
                 $tagVersion[0] = $tagVersion[0] + 1;
                 $tagVersion[1] = 0;
                 $tagVersion[2] = 0;
                 $color = "red";
                 break;
             case "MINOR":
                 $tagVersion[1] = $tagVersion[1] + 1;
                 $tagVersion[2] = 0;
                 $color = "yellow";
                 break;
             case "PATCH":
                 $tagVersion[2] = $tagVersion[2] + 1;
                 $color = "yellow";
                 break;
             case "NONE":
                 break;
             default:
                 return;
                 break;
         }
         if ($color == "red") {
             $this->error("Suggested TAG: " . implode(".", $tagVersion));
         }
         if ($color == "yellow") {
             $this->info("Suggested TAG: " . implode(".", $tagVersion));
         }
     }
     $changelog = new \Padosoft\Workbench\WorkbenchChangelog($this->workbenchSettings, $this);
     $changelogChanges = $changelog->question()->getChanges();
     $changelog->writeChangeLog($this->BASE_PATH . "CHANGELOG.md", implode(".", $tagVersion));
     $gitSimpleWrapper->git("add .");
     $gitSimpleWrapper->git('commit -m "Changelog updated"');
     $tagged = false;
     if ($this->confirm("Do you want tag the active branch?", true)) {
         do {
             $typedTagVersion = $this->ask("Type the TAG you want to use, the correct format is '#.#.#'", implode(".", $tagVersion));
             $isValid = $this->validateTAG($typedTagVersion);
             $typedTagVersioneArray = array();
             if ($isValid) {
                 $typedTagVersioneArray = explode(".", $typedTagVersion);
                 $tagValueTyped = $typedTagVersioneArray[0] * pow(10, 12) + $typedTagVersioneArray[1] * pow(10, 8) + $typedTagVersioneArray[2] * pow(10, 4);
                 $tagValue = $tagVersionOriginal[0] * pow(10, 12) + $tagVersionOriginal[1] * pow(10, 8) + $tagVersionOriginal[2] * pow(10, 4);
                 if ($tagValueTyped <= $tagValue) {
                     $this->error("Type a tag with a value greater than the previous.");
                     $isValid = false;
                 }
             }
             if ($isValid) {
                 $tagVersion[0] = $typedTagVersioneArray[0];
                 $tagVersion[1] = $typedTagVersioneArray[1];
                 $tagVersion[2] = $typedTagVersioneArray[2];
             }
             if (!$isValid) {
                 $this->error("Invalid value!");
             }
         } while (!$isValid);
         try {
             $this->tagActiveBranch($gitSimpleWrapper, implode(".", $tagVersion));
         } catch (\Exception $e) {
         }
         //
         $tagged = true;
     }
     if ($this->confirm("Do you want push the active branch?", true)) {
         $output = $this->pushOriginActiveBranch($gitSimpleWrapper, $activebranch);
         $output = str_replace($this->workbenchSettings->requested['password']['valore'], '******', $output);
         $this->line($output);
         $this->line("Active branch pushed on origin");
         if ($tagged) {
             $this->pushTagOriginActiveBranch($gitSimpleWrapper, implode(".", $tagVersion));
             $toAddToFile = "## " . implode(".", $tagVersion) . " - " . date("Y-m-d") . "\r\n";
             foreach ($changelogChanges as $key => $values) {
                 if (count($changelogChanges[$key])) {
                     $toAddToFile = $toAddToFile . "\r\n";
                     $toAddToFile = $toAddToFile . "### " . ucfirst($key) . "\r\n";
                 }
                 foreach ($changelogChanges[$key] as $change) {
                     $toAddToFile = $toAddToFile . "- " . $change . "\r\n";
                 }
             }
             $json = ["tag_name" => implode(".", $tagVersion), "target_commitish" => $activebranch, "name" => implode(".", $tagVersion), "body" => $toAddToFile, "draft" => false, "prerelease" => false];
             $response = HttpHelperFacade::sendPostJsonWithAuth("https://api.github.com/repos/" . $this->organization . "/" . $this->packagename . "/releases", $json, $this->workbenchSettings->getRequested()["user"]["valore"], $this->workbenchSettings->getRequested()["password"]["valore"]);
             $response->psr7response;
             $this->line("Tagged");
         }
     }
     /*
             if ($pushed) {
                 $this->pushTagOriginActiveBranch($gitWorkingCopy,implode(".",$tagVersion));
                 $this->line("Tagged");
             }*/
     $apiSamiGeneration = new WorkbenchApiGeneration($this->workbenchSettings, $this);
     $apiSamiGeneration->apiSamiGeneration();
     //TODO
     //chiedere messaggio di commit*
     //commit del progetto*
     //mostrare branch attivo*
     //una volta committato fare pull del progetto
     //mostrare il risultato del pull evidenziando parole tipo automerge e fail
     //chiedere se continuare
     //trovare l'ultimo tag del progetto
     //se si continua creare 2 copie del progetto, fare checkout di una delle 2 all'ultimo tag di versione
     //lanciare il confronto, evidenziare il tipo di cambiamento e suggerire la versione
     //chiedere se pushare e taggare con la nuova versione
 }