This repository was archived by the owner on May 17, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalTestCommand.php
111 lines (93 loc) · 3.49 KB
/
LocalTestCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
declare(strict_types=1);
namespace Laminas\Transfer\Command;
use Generator;
use Github\Client;
use Laminas\Transfer\Repository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function chdir;
use function explode;
use function getcwd;
use function in_array;
use function strpos;
use function system;
use const DIRECTORY_SEPARATOR;
class LocalTestCommand extends Command
{
public function configure() : void
{
$this->setName('local-test')
->setDescription('Clone github repositories and rewrite latest version to run tests locally')
->addArgument('token', InputArgument::REQUIRED, 'GitHub token')
->addOption(
'path',
'p',
InputOption::VALUE_REQUIRED,
'Path on which repositories should be checked out.',
getcwd()
);
}
public function execute(InputInterface $input, OutputInterface $output) : int
{
$token = $input->getArgument('token');
foreach ($this->repositories($token) as $repo) {
$output->writeln('<info>' . $repo . '</info>');
$path = $input->getOption('path');
$repository = new Repository($repo);
[$org, $name] = explode('/', $repository->getNewName());
$dirname = $path . DIRECTORY_SEPARATOR . $name;
system('rm -Rf ' . $dirname);
system('git clone https://github.com/' . $repo . ' ' . $dirname);
system('rm -Rf ' . $dirname . '/.git');
$currentDir = getcwd();
chdir($dirname);
system('cd ' . $dirname . ' && git init && git add . && git commit -am "original"');
system(__DIR__ . '/../../bin/console rewrite ' . $repo);
system(
'cd ' . $dirname . ' && \
composer config repositories.laminas composer https://laminas.mwop.net/repo/testing && \
git add . && \
git commit -am "' . $name . ': rewrite test 3"'
);
if (strpos($name, 'mezzio') === 0) {
$org = 'mezzio-dev';
} elseif (strpos($name, 'api-') === 0) {
$org = 'laminas-api-tools-dev';
} else {
$org = 'laminas-dev';
}
system(
'cd ' . $dirname . ' && \
git remote add origin git@github.com:' . $org . '/' . $name . '.git && \
git push origin --set-upstream master:master -f'
);
chdir($currentDir);
}
return 0;
}
protected function repositories(string $token) : Generator
{
$client = new Client();
$client->authenticate($token, null, $client::AUTH_URL_TOKEN);
foreach (['zendframework', 'zfcampus'] as $org) {
$page = 1;
while (true) {
$repos = $client->organization()->repositories($org, 'all', $page);
++$page;
if (! $repos) {
break;
}
foreach ($repos as $repo) {
if (in_array($repo['name'], DependenciesCommand::SKIP, true)) {
continue;
}
yield $org . '/' . $repo['name'];
}
}
}
}
}