Skip to content

Commit

Permalink
Merge pull request #48 from statamic/fix/overzealous-github-auth-check
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite authored Mar 15, 2022
2 parents 7879fb3 + 8fd15eb commit 48db514
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class NewCommand extends Command
public $name;
public $version;
public $starterKit;
public $starterKitVcs;
public $starterKitLicense;
public $local;
public $withConfig;
Expand Down Expand Up @@ -88,8 +87,6 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this
->askForRepo()
->detectRepoVcs()
->detectMissingVcsAuth()
->validateStarterKitLicense()
->installBaseProject()
->installStarterKit()
Expand Down Expand Up @@ -278,54 +275,6 @@ protected function askForRepo()
return $this;
}

/**
* Detect starter kit repo vcs, using same precedence logic used in statamic/cms.
*
* @return $this
*/
protected function detectRepoVcs()
{
if ($this->local) {
return $this;
}

$request = new Client(['http_errors' => false]);

if ($request->get("https://repo.packagist.org/p2/{$this->starterKit}.json")->getStatusCode() === 200) {
return $this;
}

if ($request->get("https://github.com/{$this->starterKit}")->getStatusCode() === 200) {
$this->starterKitVcs = 'github';
} elseif ($request->get($bitbucketUrl = "https://bitbucket.org/{$this->starterKit}.git")->getStatusCode() === 200) {
$this->starterKitVcs = 'bitbucket';
} elseif ($request->get($gitlabUrl = "https://gitlab.com/{$this->starterKit}")->getStatusCode() === 200) {
$this->starterKitVcs = 'gitlab';
}

return $this;
}

/**
* Detect missing starter kit repo vcs auth, and prompt user to properly authenticate.
*
* @return $this
*/
protected function detectMissingVcsAuth()
{
if ($this->starterKitVcs === 'github' && $this->hasMissingComposerToken('github-oauth.github.com')) {
$this->output->write(PHP_EOL);
$this->output->write('<error>Composer could not authenticate with GitHub!</error>'.PHP_EOL);
$this->output->write('<comment>Please generate a personal access token at: https://github.com/settings/tokens/new</comment>'.PHP_EOL);
$this->output->write('<comment>Then save your token for future use by running the following command:</comment>'.PHP_EOL);
$this->output->write('<comment>composer config --global --auth github-oauth.github.com [your-token-here]</comment>'.PHP_EOL);

return $this->exitInstallation();
}

return $this;
}

/**
* Validate starter kit license.
*
Expand Down Expand Up @@ -816,21 +765,6 @@ protected function getStarterKitLicense()
return $license;
}

/**
* Check if user has missing composer token.
*
* @param string $tokenKey
* @return bool
*/
protected function hasMissingComposerToken($tokenKey)
{
$composer = $this->findComposer();

return ! $this
->runCommand("{$composer} config --global --auth {$tokenKey}", true)
->isSuccessful();
}

/**
* Exit installation.
*
Expand Down

0 comments on commit 48db514

Please sign in to comment.