Files
web-rmtools/include/Repository.php
Christoph M. Becker 7bc1c7900f Add general support for exporting from a Github mirror
This is a follow up on the quick fix for exporting from the php-src
Github mirror[1].  Instead of hard-coding everything in the code, we
introduce a configurable `gh_url`, and use it if given.  We cannot use
the repository URL, though, because the toplevel folder inside the
downloaded archive would have a different name (the shortened revision
number is expanded again); downloading from the codeload subdomain
gives the desired result.

[1] <9e1ca1002a>
2020-09-07 13:42:26 +02:00

40 lines
995 B
PHP

<?php
namespace rmtools;
include __DIR__ . '/Svn.php';
include __DIR__ . '/Git.php';
class Repository {
public static function fromBranchConfig(BranchConfig $config)
{
$name = $config->getRepoName();
$config_path = __DIR__ . '/../data/config/repo/' . $name . '.ini';
if (!is_readable($config_path)) {
throw new \Exception('Cannot open repo data <' . $config_path . '>');
}
$repo = parse_ini_file($config_path, true,INI_SCANNER_RAW);
if (!$repo) {
throw new \Exception('Cannot parse config file <' . $config_path . '>');
}
if (!isset($repo['type'])) {
throw new \Exception('Invalid repo config data, no type defined');
}
switch ($repo['type']) {
case 'svn':
$r = new Svn($repo['url']);
return $r;
break;
case 'git':
$r = new Git($repo['url'], isset($repo['gh_url']) ? $repo['gh_url'] : null);
return $r;
break;
default:
throw new \Exception('Invalid repo config data, invalid type defined');
}
}
}