Skip to content

Commit d52db3a

Browse files
authored
Merge pull request #6 from ibexa-yuna/master
GPT-3.5: Change execution to multi-package require
2 parents f4e5ba2 + 036f287 commit d52db3a

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/Command/CheckoutCommand.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,40 @@ protected function configure(): void
2424
protected function execute(InputInterface $input, OutputInterface $output): int
2525
{
2626
$pullRequestUrls = $this->validateInput($input->getArgument('pullRequestUrls'));
27-
28-
$preferSource = $input->hasOption('prefer-source');
29-
27+
$preferSource = $input->getOption('prefer-source');
28+
29+
$packages = [];
3030
foreach ($pullRequestUrls as $pullRequestUrl) {
3131
$githubPullRequestData = GithubPullRequestData::fromUrl($pullRequestUrl);
3232
$composerPullRequestData = $this->extractDataFromPullRequest($githubPullRequestData);
3333
$this->addRepository($composerPullRequestData->repositoryUrl, $output);
34-
$this->requireDependency($composerPullRequestData, $output, $preferSource);
34+
35+
$dependencyString = sprintf('dev-%s as %s', $composerPullRequestData->branchName, $composerPullRequestData->branchAlias);
36+
$packages[] = sprintf("%s:%s", $composerPullRequestData->packageName, $dependencyString);
3537
}
36-
38+
39+
$inputArray = [
40+
'packages' => $packages,
41+
'--no-scripts' => true,
42+
];
43+
44+
if ($preferSource) {
45+
$inputArray['--prefer-source'] = true;
46+
}
47+
48+
/** @var RequireCommand */
49+
$requireCommand = $this->getApplication()->get('require');
50+
if ($requireCommand->run(new ArrayInput($inputArray), $output)) {
51+
throw new \RuntimeException('Failed on adding dependencies');
52+
}
53+
54+
$this->resetComposer();
3755
$this->executePostInstallCommands($output);
38-
56+
3957
return 0;
4058
}
4159

60+
4261
private function addRepository(string $repositoryUrl, OutputInterface $output): void
4362
{
4463
/** @var ConfigCommand $configCommand */
@@ -51,9 +70,7 @@ private function addRepository(string $repositoryUrl, OutputInterface $output):
5170

5271
if ($configCommand->run($input, $output)) {
5372
throw new \RuntimeException('Something wrong happened when adding repository');
54-
}
55-
56-
$this->resetComposer();
73+
}
5774
}
5875

5976
private function extractDataFromPullRequest(GithubPullRequestData $pullRequestData): ComposerPullRequestData
@@ -69,7 +86,7 @@ private function extractDataFromPullRequest(GithubPullRequestData $pullRequestDa
6986
$this->getDownloader()
7087
->get($pullRequestDataRequestUrl)
7188
->getBody(),
72-
true
89+
true
7390
);
7491

7592
$targetBranch = $pullRequestDetails['base']['ref'];

0 commit comments

Comments
 (0)