Inheritance: extends Symfony\Component\Console\Helper\Helper, implements Gush\Helper\OutputAwareInterface, implements Symfony\Component\Console\Input\InputAwareInterface, implements Symfony\Component\Console\Style\StyleInterface
Ejemplo n.º 1
0
 /**
  * Retrieves the requirements of the given template and asks the
  * user for any parameters that are not available from the
  * input, then binds the parameters to the template.
  *
  * @param TemplateInterface $template Template to render
  */
 public function parameterize(TemplateInterface $template)
 {
     $params = [];
     foreach ($template->getRequirements() as $key => $requirement) {
         if (!$this->input->hasOption($key) || !$this->input->getOption($key)) {
             list($prompt, $default) = $requirement;
             if ('description' === $key) {
                 $v = $this->style->ask($prompt . ' (enter "e" to open editor)', $default);
                 if ('e' === $v) {
                     $editor = $this->getHelperSet()->get('editor');
                     $v = $editor->fromString('');
                 }
             } else {
                 if ('branch' === $key && $this->input->hasOption('base') && $this->input->getOption('base')) {
                     $default = $this->input->getOption('base');
                 }
                 if (1 < count($choices = explode('|', $default))) {
                     $v = $this->style->choice($prompt . ' ', $choices, $choices[0]);
                 } else {
                     $v = $this->style->ask($prompt . ' ', $default);
                 }
             }
         } else {
             $v = $this->input->getOption($key);
         }
         $params[$key] = $v;
     }
     $template->bind($params);
 }
Ejemplo n.º 2
0
 private function createAuthorization(Client $client, $code = null)
 {
     $scopes = ['user:email', 'repo', 'repo:status', 'read:org'];
     // Use a date with time to make sure the name is unique.
     // It's not possible to get existing authorizations, only to create new ones.
     $time = (new \DateTime('now', new \DateTimeZone('UTC')))->format('Y-m-d\\TH:i:s \\U\\T\\C');
     $authorization = $client->api('authorizations')->create(['note' => sprintf('Gush on %s at %s', gethostname(), $time), 'scopes' => $scopes], $code);
     // NB. This message will be only shown when eg. fa2 is disabled or the 2fa code was correct.
     // Else the create() in authorizations will throw an exception.
     $this->styleHelper->success('Successfully authenticated, token note: ' . $authorization['note']);
     return $authorization;
 }
Ejemplo n.º 3
0
 private function guardRemoteBranchExist($org, $repo, $branch, StyleHelper $styleHelper)
 {
     /** @var GitHelper $gitHelper */
     $gitHelper = $this->getHelper('git');
     $gitUrl = $this->getAdapter()->getRepositoryInfo($org, $repo)['push_url'];
     if ($gitHelper->remoteBranchExists($gitUrl, $branch)) {
         return;
         // branch exists, continue
     }
     if ($gitHelper->branchExists($branch)) {
         $this->guardRemoteUpdated($org, $repo);
         $gitHelper->pushToRemote($org, $branch, true);
         $styleHelper->note(sprintf('Branch "%s" was pushed to "%s".', $branch, $org));
         return;
     }
     throw new UserException(sprintf('Cannot open pull-request, remote branch "%s" does not exist in "%s/%s".', $branch, $org, $repo));
 }
Ejemplo n.º 4
0
 private function getIssueLabels(array $labels, StyleHelper $style)
 {
     if (0 === count($labels)) {
         $style->writeln(' N/A');
         $style->newLine();
         return;
     }
     $style->listing($labels);
 }