From 15688bdf7dc24b1085f3ee1f0e1ffb8a05f91acd Mon Sep 17 00:00:00 2001 From: Paul Sohier Date: Sun, 21 Apr 2019 20:54:02 +0200 Subject: [PATCH 1/2] Add support to use a personal access token for github Fixes #89 --- src/Tests/TestStartup.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Tests/TestStartup.php b/src/Tests/TestStartup.php index c0453f9..4d67b17 100644 --- a/src/Tests/TestStartup.php +++ b/src/Tests/TestStartup.php @@ -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 * @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; @@ -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; } @@ -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(); @@ -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; @@ -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) { From 2756a05d0686ef5b5a64af1451fee0b2e12e6f46 Mon Sep 17 00:00:00 2001 From: Paul Sohier Date: Sun, 21 Apr 2019 20:57:00 +0200 Subject: [PATCH 2/2] Fix CS --- src/Tests/TestStartup.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Tests/TestStartup.php b/src/Tests/TestStartup.php index 4d67b17..dcaa17a 100644 --- a/src/Tests/TestStartup.php +++ b/src/Tests/TestStartup.php @@ -36,9 +36,9 @@ 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 + * @parm $oauth_token string The personal oauth string to use * @param string $branch When using GIT and GITHUB you can provide a branch name. When empty, defaults to master - * @throws TestException + * @throws TestException */ public function __construct(OutputInterface $output, $type, $location, $debug, $oauth = '', $branch = '') { @@ -71,7 +71,7 @@ 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 + * @param string $oauth Personal oauth string to use * * @throws Exception\TestException * @return string local directory of the cloned repo @@ -95,10 +95,10 @@ private function initGit($git, $branch, $oauth) } if (!empty($oauth) && strpos($git, 'https://github.com') !== false) - { - $oauth = $oauth . ':x-oauth-basic@'; - $git = str_replace('github.com', $oauth . 'github.com', $git); - } + { + $oauth = $oauth . ':x-oauth-basic@'; + $git = str_replace('github.com', $oauth . 'github.com', $git); + } Admin::cloneBranchTo($uniq, $git, $branch, false); @@ -109,7 +109,7 @@ private function initGit($git, $branch, $oauth) * Run the test suite with the current directory. * * @param boolean $printDir print directory information - * @throws TestException + * @throws TestException */ private function runTests($printDir = true) {