From 0e3e1a978f442825cdc936794aace5f4eca68450 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 19 Dec 2017 21:57:30 -0500 Subject: [PATCH] Remove dead PHP code --- php/mass-rebuild-filter.php | 5 -- php/poster.php | 8 +- php/src/ACL.php | 25 ------ php/src/Checkout.php | 119 --------------------------- php/src/CommitStatus.php | 49 ----------- php/src/Exec.php | 42 ---------- php/src/NixBuild.php | 3 - php/src/RebuildTagClassifier.php | 62 -------------- php/src/TestExec.php | 68 --------------- php/src/TestRebuildTagClassifier.php | 101 ----------------------- 10 files changed, 1 insertion(+), 481 deletions(-) delete mode 100644 php/src/Checkout.php delete mode 100644 php/src/CommitStatus.php delete mode 100644 php/src/Exec.php delete mode 100644 php/src/NixBuild.php delete mode 100644 php/src/RebuildTagClassifier.php delete mode 100644 php/src/TestExec.php delete mode 100644 php/src/TestRebuildTagClassifier.php diff --git a/php/mass-rebuild-filter.php b/php/mass-rebuild-filter.php index 2b6ca5f..92aa512 100644 --- a/php/mass-rebuild-filter.php +++ b/php/mass-rebuild-filter.php @@ -21,11 +21,6 @@ echo "hi\n"; function outrunner($msg) { try { runner($msg); - } catch (\GHE\ExecException $e) { - var_dump($msg); - var_dump($e->getMessage()); - var_dump($e->getCode()); - var_dump($e->getOutput()); } catch (\PhpAmqpLib\Exception\AMQPProtocolChannelException $e) { echo "Channel exception:\n"; var_dump($e); diff --git a/php/poster.php b/php/poster.php index e692623..6de42cf 100644 --- a/php/poster.php +++ b/php/poster.php @@ -76,13 +76,7 @@ function reply_to_issue($body, $output, $success, $system) { function outrunner($msg) { - try { - return runner($msg); - } catch (GHE\ExecException $e) { - var_dump($e->getMessage()); - var_dump($e->getCode()); - var_dump($e->getOutput()); - } + return runner($msg); } diff --git a/php/src/ACL.php b/php/src/ACL.php index e453218..e9e14be 100644 --- a/php/src/ACL.php +++ b/php/src/ACL.php @@ -10,32 +10,7 @@ class ACL { ]; } - static public function getUsers() { - return [ - '7c6f434c', - 'copumpkin', - 'disassembler', - 'domenkozar', - 'fpletz', - 'fridh', - 'globin', - 'grahamc', - 'lnl7', - 'mic92', - 'orivej', - 'shlevy', - ]; - } - static public function isRepoEligible($repo) { return in_array(strtolower($repo), self::getRepos()); } - - static public function isUserAuthorized($user) { - return in_array(strtolower($user), self::getUsers()); - } - - static public function authorizeUserRepo($user, $repo) { - return self::isRepoEligible($repo) && self::isUserAuthorized($user); - } } \ No newline at end of file diff --git a/php/src/Checkout.php b/php/src/Checkout.php deleted file mode 100644 index f410a1e..0000000 --- a/php/src/Checkout.php +++ /dev/null @@ -1,119 +0,0 @@ -root = $root; - $this->type = $type; - } - - function checkOutRef($repo_name, $clone_url, $id, $ref) { - $this->prefetchRepoCache($repo_name, $clone_url); - - $pname = $this->pathToRepoCache($repo_name); - $bname = $this->pathToBuildDir($repo_name, $id); - - $guard = $this->guard($bname); - if (!is_dir($bname)) { - echo "Cloning https://github.com/" . $repo_name . "/pull/" . $id . " to $bname\n"; - Exec::exec('git clone --shared --reference-if-able %s %s %s', - [ - $pname, - $clone_url, - $bname - ]); - } - - if (!chdir($bname)) { - throw new CoFailedException("Failed to chdir to $bname\n"); - } - - echo "fetching https://github.com/" . $repo_name . "/pull/" . $id . " in $bname\n"; - Exec::exec('git fetch origin'); - try { - Exec::exec('git am --abort'); - } catch (ExecException $e) { - // non-zero exit if no am is in progress - } - Exec::exec('git reset --hard %s', [$ref]); - - - $this->release($guard); - - return $bname; - } - - function applyPatches($bname, $patch_url) { - if (!chdir($bname)) { - throw new CoFailedException("Failed to chdir to $bname\n"); - } - - $guard = $this->guard($bname); - Exec::exec('curl -L %s | git am --no-gpg-sign -', [$patch_url]); - $this->release($guard); - } - - function prefetchRepoCache($name, $clone_url) { - if (!chdir($this->root)) { - throw new CoFailedException("Failed to chdir to " . $this->root); - } - - $pname = $this->pathToRepoCache($name); - - $guard = $this->guard($pname); - - if (!is_dir($pname)) { - echo "Cloning " . $name . " to $pname\n"; - Exec::exec('git clone --bare %s %s', - [ - $clone_url, - $pname - ]); - } - - $this->release($guard); - - if (!chdir($pname)) { - throw new CoFailedException("Failed to chdir to $pname"); - } - - echo "Fetching $name in $pname\n"; - Exec::exec('git fetch origin'); - } - - function pathToRepoCache($name) { - return $this->root . "/repo-" . md5($name); - } - - function pathToBuildDir($repo, $id_number) { - $id = (int) $id_number; - $repo_hash = md5($repo); - $type = $this->type; - - return $this->root . "/$type-$repo_hash-$id"; - } - - function guard($path) { - echo "about to lock $path\n"; - $res = fopen("$path.lock", 'c'); - while (!flock($res, LOCK_EX)) { - echo "waiting for lock on $path...\n"; - sleep(1); - } - echo "got lock on $path\n"; - - return $res; - } - - function release($res) { - fclose($res); - } - -} - -class CoFailedException extends \Exception {} \ No newline at end of file diff --git a/php/src/CommitStatus.php b/php/src/CommitStatus.php deleted file mode 100644 index f37d586..0000000 --- a/php/src/CommitStatus.php +++ /dev/null @@ -1,49 +0,0 @@ -ghclient = $ghclient; - $this->owner = $owner; - $this->repo = $repo; - $this->sha = $sha; - $this->name = $name; - } - - public function pending($description) { - $this->mark('pending', $description); - } - - public function error($description) { - $this->mark('error', $description); - } - - public function failure($description) { - $this->mark('failure', $description); - } - - public function success($description) { - $this->mark('success', $description); - } - - public function mark($state, $description) { - $this->ghclient->api('repository')->statuses()->create( - $this->owner, - $this->repo, - $this->sha, - [ - 'state' => $state, - 'context' => $this->name, - 'description' => $description, - ] - ); - } -} diff --git a/php/src/Exec.php b/php/src/Exec.php deleted file mode 100644 index aa05bfa..0000000 --- a/php/src/Exec.php +++ /dev/null @@ -1,42 +0,0 @@ -&1', - escapeshellarg($interiorCmd)); - - exec($exteriorCmd, $output, $return); - - if ($return > 0) { - throw new ExecException($cmd, $args, $output, $return); - } - - return $output; - } -} - -class ExecException extends \Exception { - protected $args; - protected $output; - - public function __construct($cmd, $args, $output, $return) { - $this->args = $args; - $this->output = $output; - - parent::__construct("Error calling $cmd", $return); - } - - public function getArgs() { - return $this->args; - } - - public function getOutput() { - return $this->output; - } - -} \ No newline at end of file diff --git a/php/src/NixBuild.php b/php/src/NixBuild.php deleted file mode 100644 index ab2eb15..0000000 --- a/php/src/NixBuild.php +++ /dev/null @@ -1,3 +0,0 @@ - $count) { - $label[] = self::labelForArchCount($arch, $count); - } - - return $label; - } - - public static function parse($output) { - $counts = []; - foreach ($output as $line) { - if (preg_match('/^\s*(\d+) (.*)$/', $line, $matches)) { - $counts[$matches[2]] = (int)$matches[1]; - } - } - - return $counts; - } - - public static function labelForArchCount($arch, $count) { - if ($arch == "x86_64-linux") { - $prefix = "10.rebuild-linux: "; - } elseif ($arch == "x86_64-darwin") { - $prefix = "10.rebuild-darwin: "; - } else { - throw new RebuildTagClassifierArchException("Unknown arch $arch"); - } - - if ($count > 500) { - $suffix = "501+"; - } else if ($count > 100) { - $suffix = "101-500"; - } else if ($count > 10) { - $suffix = "11-100"; - } else if ($count > 0) { - $suffix = "1-10"; - } else { - $suffix = "0"; - } - - return $prefix . $suffix; - } -} - -class RebuildTagClassifierArchException extends \Exception {} \ No newline at end of file diff --git a/php/src/TestExec.php b/php/src/TestExec.php deleted file mode 100644 index 72bc178..0000000 --- a/php/src/TestExec.php +++ /dev/null @@ -1,68 +0,0 @@ -assertEquals( - ['oof'], - Exec::exec('echo foo | rev') - ); - } - - function testExecArgs() { - $this->assertEquals( - ['rab'], - Exec::exec('echo %s | rev', ['bar']) - ); - } - - function testExecArgsDangerous() { - $this->assertEquals( - ['$(whoami)'], - Exec::exec('echo %s', ['$(whoami)']) - ); - } - - function testExecFailureExceptions() { - $this->expectException(ExecException::class); - $this->expectExceptionCode(123); - $this->expectExceptionMessage("Error calling exit 123"); - Exec::exec('exit 123'); - } - - function testExecFailureExceptionsOutput() { - try { - Exec::exec('echo %s; exit %s', ["heya", 10]); - $this->assertFalse(true, "Should have excepted!"); - } catch (ExecException $e) { - $this->assertEquals(10, $e->getCode()); - $this->assertEquals(["heya", 10], $e->getArgs()); - $this->assertEquals(["heya"], $e->getOutput()); - } - } - - - function testExecFailureExceptionPipefailEnd() { - try { - var_dump(Exec::exec('echo "foo" | (exit 2);')); - $this->assertFalse(true, "Should have excepted!"); - } catch (ExecException $e) { - $this->assertEquals(2, $e->getCode()); - } - } - - function testExecFailureExceptionPipefailStart() { - try { - var_dump(Exec::exec('(echo "foo"; exit 3) | rev;')); - $this->assertFalse(true, "Should have excepted!"); - } catch (ExecException $e) { - $this->assertEquals(3, $e->getCode()); - } - } - -} \ No newline at end of file diff --git a/php/src/TestRebuildTagClassifier.php b/php/src/TestRebuildTagClassifier.php deleted file mode 100644 index 799af36..0000000 --- a/php/src/TestRebuildTagClassifier.php +++ /dev/null @@ -1,101 +0,0 @@ -assertEquals( - ["10.rebuild-linux: 1-10", "10.rebuild-darwin: 0"], - RebuildTagClassifier::parseAndLabel([ - "Estimating rebuild amount by counting changed Hydra jobs.", - " 1 x86_64-linux", - ])); - } - - function testExecParseAndLabelGarbage() { - $this->assertEquals( - ["10.rebuild-darwin: 0", "10.rebuild-linux: 0", ], - RebuildTagClassifier::parseAndLabel(["foo", "bar"]) - ); - } - - function testExecParseAndLabelLinuxOnly() { - $this->assertEquals( - ["10.rebuild-linux: 1-10", "10.rebuild-darwin: 0", ], - RebuildTagClassifier::parseAndLabel([" 5 x86_64-linux"]) - ); - } - - function testExecParseAndLabelDarwinOnly() { - $this->assertEquals( - ["10.rebuild-darwin: 1-10", "10.rebuild-linux: 0", ], - RebuildTagClassifier::parseAndLabel([" 5 x86_64-darwin"]) - ); - } - - function testExecParseAndLabelLinuxAndDarwin() { - $this->assertEquals( - ["10.rebuild-linux: 1-10", "10.rebuild-darwin: 11-100", ], - RebuildTagClassifier::parseAndLabel([" 5 x86_64-linux", " 17 x86_64-darwin"]) - ); - } - - - - function testExecParseNone() { - $this->assertEquals( - [], - RebuildTagClassifier::parse([]) - ); - } - - function testExecParseGarbage() { - $this->assertEquals( - [], - RebuildTagClassifier::parse(["foo", "bar"]) - ); - } - - function testExecParseLinuxOnly() { - $this->assertEquals( - ["x86_64-linux" => 5], - RebuildTagClassifier::parse([" 5 x86_64-linux"]) - ); - } - - function testParseJustOne() { - $this->assertEquals( - ["x86_64-linux" => 1], - RebuildTagClassifier::parse([ - "Estimating rebuild amount by counting changed Hydra jobs.", - " 1 x86_64-linux", - ])); - } - - function testExecParseDarwinOnly() { - $this->assertEquals( - ["x86_64-darwin" => 5], - RebuildTagClassifier::parse([" 5 x86_64-darwin"]) - ); - } - - function testExecParseLinuxAndDarwin() { - $this->assertEquals( - ["x86_64-linux" => 5, "x86_64-darwin" => 17], - RebuildTagClassifier::parse([" 5 x86_64-linux", " 17 x86_64-darwin"]) - ); - } - - function testLabelForArchCount() { - $this->assertEquals("10.rebuild-linux: 501+", RebuildTagClassifier::labelForArchCount("x86_64-linux", 501)); - $this->assertEquals("10.rebuild-linux: 101-500", RebuildTagClassifier::labelForArchCount("x86_64-linux", 150)); - $this->assertEquals("10.rebuild-darwin: 101-500", RebuildTagClassifier::labelForArchCount("x86_64-darwin", 150)); - } - - function testLabelForUnknownArch() { - $this->expectException(RebuildTagClassifierArchException::class); - RebuildTagClassifier::labelForArchCount("lmao", 150); - } -} \ No newline at end of file