Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions GithubComment/Helper/GithubHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Client as Github;
use Github\Exception\RuntimeException;
use Github\Exception\TwoFactorAuthenticationRequiredException;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -44,6 +45,7 @@ public function getCredentials(InputInterface $input, OutputInterface $output)
private function createToken(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getHelperSet()->get('question');

$username = $dialog->ask($input, $output, new Question('<info>Your Github username:</info> '));
$question = new Question('<info>Your Github password:</info> ');
$question->setHidden(true);
Expand All @@ -55,6 +57,17 @@ private function createToken(InputInterface $input, OutputInterface $output)
$token = $github->api('authorizations')->create(array('scopes' => array('repo'), 'note' => $this->name));

return ['username' => $username, 'token' => $token['token']];
} catch (TwoFactorAuthenticationRequiredException $e) {
try {
$question = new Question('<info>The account has two-factor authentication enabled, please provide the code for this request:</info> ');
$code = $dialog->ask($input, $output, $question);

$token = $github->api('authorizations')->create(array('scopes' => array('repo'), 'note' => $this->name), $code);

return array('username' => $username, 'token' => $token['token']);
} catch (RuntimeException $e) {
return false;
}
} catch (RuntimeException $e) {
return false;
}
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.