-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from vtsykun/feat/asset-repo-support
Support asset repo type and any repository without composer.json file
- Loading branch information
Showing
12 changed files
with
247 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packeton\Composer; | ||
|
||
interface DriverFactoryAwareInterface | ||
{ | ||
public function setDriverFactory(VcsDriverFactory $factory): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packeton\Composer\Repository\Vcs; | ||
|
||
use Composer\Config; | ||
use Composer\IO\IOInterface; | ||
use Composer\Repository\Vcs\VcsDriver; | ||
use Packeton\Composer\DriverFactoryAwareInterface; | ||
use Packeton\Composer\VcsDriverFactory; | ||
|
||
class AssetVcsDriver extends VcsDriver implements DriverFactoryAwareInterface | ||
{ | ||
private VcsDriver $driver; | ||
private VcsDriverFactory $driverFactory; | ||
|
||
public function initialize(): void | ||
{ | ||
$repoConfig = $this->repoConfig; | ||
$repoConfig['driver'] = 'vcs'; | ||
$repoConfig['repoType'] = 'vcs'; | ||
|
||
$this->driver = $this->driverFactory->createDriver( | ||
repoConfig: $repoConfig, | ||
io: $this->io, | ||
config: $this->config, | ||
httpDownloader: $this->httpDownloader, | ||
process: $this->process, | ||
classOrType: $repoConfig['driver'], | ||
options: ['url' => $repoConfig['url']], | ||
); | ||
} | ||
|
||
public function getComposerInformation(string $identifier): ?array | ||
{ | ||
$composer = $this->repoConfig['customComposerJson'] ?? []; | ||
if ($this->repoConfig['packageName'] ?? null) { | ||
$composer['name'] = $this->repoConfig['packageName']; | ||
} | ||
|
||
if (empty($composer['time']) && null !== ($changeDate = $this->getChangeDate($identifier))) { | ||
$composer['time'] = $changeDate->format(DATE_RFC3339); | ||
} | ||
|
||
return $composer; | ||
} | ||
|
||
public function getFileContent(string $file, string $identifier): ?string | ||
{ | ||
return $this->driver->getFileContent($file, $identifier); | ||
} | ||
|
||
public function getChangeDate(string $identifier): ?\DateTimeImmutable | ||
{ | ||
return $this->driver->getChangeDate($identifier); | ||
} | ||
|
||
public function getRootIdentifier(): string | ||
{ | ||
return $this->driver->getRootIdentifier(); | ||
} | ||
|
||
public function getBranches(): array | ||
{ | ||
return $this->driver->getBranches(); | ||
} | ||
|
||
public function getTags(): array | ||
{ | ||
return $this->driver->getTags(); | ||
} | ||
|
||
public function getDist(string $identifier): ?array | ||
{ | ||
return $this->driver->getDist($identifier); | ||
} | ||
|
||
public function getSource(string $identifier): array | ||
{ | ||
return $this->driver->getSource($identifier); | ||
} | ||
|
||
public function getUrl(): string | ||
{ | ||
return $this->driver->getUrl(); | ||
} | ||
|
||
public function hasComposerFile(string $identifier): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function cleanup(): void | ||
{ | ||
$this->driver->cleanup(); | ||
} | ||
|
||
public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function setDriverFactory(VcsDriverFactory $factory): void | ||
{ | ||
$this->driverFactory = $factory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packeton\Form\Type\Package; | ||
|
||
use Packeton\Form\Type\CredentialType; | ||
use Packeton\Form\Type\JsonTextType; | ||
use Packeton\Model\PackageManager; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormEvents; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
|
||
class AssetPackageType extends AbstractType | ||
{ | ||
use VcsPackageTypeTrait; | ||
|
||
public function __construct(private readonly PackageManager $packageManager) | ||
{ | ||
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder->remove('pullRequestReview'); | ||
|
||
$builder | ||
->add('credentials', CredentialType::class) | ||
->add('repository', TextType::class, [ | ||
'label' => 'Repository URL (Git/Svn/Hg)', | ||
'attr' => [ | ||
'class' => 'package-repo-info', | ||
'placeholder' => 'e.g.: https://github.com/fullcalendar/fullcalendar', | ||
], | ||
'constraints' => [new NotBlank()], | ||
]) | ||
->add('name', TextType::class, [ | ||
'required' => true, | ||
'constraints' => [new NotBlank()], | ||
'attr' => ['class' => 'package-repo-info', 'placeholder' => 'npm-asset/select2'], | ||
'disabled' => false === $options['is_created'], | ||
]); | ||
|
||
$placeholder = [ | ||
'name' => 'npm-asset/select2', | ||
'description' => 'Select2 is a jQuery-based replacement for select boxes.', | ||
'require' => ['php' => '>8.1'], | ||
'autoload' => ['psr-4' => ['Packeton\\' => 'src/']] | ||
]; | ||
|
||
$builder | ||
->add('customComposerJson', JsonTextType::class, [ | ||
'required' => false, | ||
'label' => 'composer.json config', | ||
'attr' => ['rows' => 12, 'placeholder' => json_encode($placeholder, 448)] | ||
]); | ||
|
||
$builder->addEventListener(FormEvents::POST_SUBMIT, $this->updateRepository(...), 255); | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return BasePackageType::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packeton\Form\Type\Package; | ||
|
||
use Packeton\Entity\Package; | ||
use Symfony\Component\Form\FormEvent; | ||
|
||
trait VcsPackageTypeTrait | ||
{ | ||
public function updateRepository(FormEvent $event): void | ||
{ | ||
$package = $event->getData(); | ||
if ($package instanceof Package) { | ||
$this->packageManager->updatePackageUrl($package); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters