Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to use a personal access token for github #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions src/Tests/TestStartup.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ class TestStartup
* @param $type int Type what the location is
* @param $location string Location where the extension is
* @param $debug boolean if debug is enabled
* @parm $oauth_token string The personal oauth string to use
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @parm $oauth_token string The personal oauth string to use
* @param $oauth_token string The personal oauth string to use

Typo

* @param string $branch When using GIT and GITHUB you can provide a branch name. When empty, defaults to master
* @throws TestException
*/
public function __construct(OutputInterface $output, $type, $location, $debug, $branch = '')
public function __construct(OutputInterface $output, $type, $location, $debug, $oauth = '', $branch = '')
{
$this->output = $output;
$rundir = true;
Expand All @@ -51,7 +53,7 @@ public function __construct(OutputInterface $output, $type, $location, $debug, $

if ($type == self::TYPE_GIT)
{
$location = $this->initGit($location, $branch);
$location = $this->initGit($location, $branch, $oauth);
$rundir = false;
}

Expand All @@ -69,18 +71,18 @@ public function __construct(OutputInterface $output, $type, $location, $debug, $
*
* @param string $git Location of the git repo
* @param string $branch branch to checkout
* @param string $oauth Personal oauth string to use
*
* @throws Exception\TestException
* @return string local directory of the cloned repo
*/
private function initGit($git, $branch)
private function initGit($git, $branch, $oauth)
{
if (empty($branch))
{
$branch = 'master';
}


$this->output->writeln(sprintf("Checkout %s from git on branch %s.", $git, $branch));
$tmpdir = sys_get_temp_dir();
$uniq = $tmpdir . DIRECTORY_SEPARATOR . uniqid();
Expand All @@ -92,6 +94,12 @@ private function initGit($git, $branch)
throw new TestException('Unable to create tmp directory');
}

if (!empty($oauth) && strpos($git, 'https://github.com') !== false)
{
$oauth = $oauth . ':x-oauth-basic@';
$git = str_replace('github.com', $oauth . 'github.com', $git);
}

Admin::cloneBranchTo($uniq, $git, $branch, false);

return $uniq;
Expand All @@ -101,6 +109,7 @@ private function initGit($git, $branch)
* Run the test suite with the current directory.
*
* @param boolean $printDir print directory information
* @throws TestException
*/
private function runTests($printDir = true)
{
Expand Down