diff --git a/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php b/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php index c32aeba..a8c24ce 100644 --- a/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php +++ b/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php @@ -22,6 +22,7 @@ use MBO\SatisGitlab\Filter\IgnoreRegexpFilter; use MBO\SatisGitlab\Filter\IncludeIfHasFileFilter; +use MBO\SatisGitlab\Filter\ProjectTypeFilter; @@ -61,6 +62,7 @@ protected function configure() { */ ->addOption('ignore', 'i', InputOption::VALUE_REQUIRED, 'ignore project according to a regexp, for ex : "(^phpstorm|^typo3\/library)"', null) ->addOption('include-if-has-file',null,InputOption::VALUE_REQUIRED, 'include in satis config if project contains a given file, for ex : ".satisinclude"', null) + ->addOption('project-type',null,InputOption::VALUE_REQUIRED, 'include in satis config if project is of a specified type, for ex : "library"', null) /* * satis config generation options */ @@ -121,6 +123,14 @@ protected function execute(InputInterface $input, OutputInterface $output) { $logger )); } + /* project-type option */ + if ( ! empty($input->getOption('project-type')) ){ + $filterCollection->addFilter(new ProjectTypeFilter( + $input->getOption('project-type'), + $client, + $logger + )); + } /* * Create configuration builder diff --git a/src/MBO/SatisGitlab/Filter/ProjectTypeFilter.php b/src/MBO/SatisGitlab/Filter/ProjectTypeFilter.php new file mode 100644 index 0000000..d72eab4 --- /dev/null +++ b/src/MBO/SatisGitlab/Filter/ProjectTypeFilter.php @@ -0,0 +1,66 @@ +projectType = $type; + $this->gitClient = $gitClient; + $this->logger = $logger; + } + + /** + * {@inheritDoc} + */ + public function isAccepted(ProjectInterface $project) + { + try { + $json = $this->gitClient->getRawFile( + $project, + 'composer.json', + $project->getDefaultBranch() + ); + $composer = json_decode($json, true); + return isset($composer['type']) && strtolower($composer['type']) === strtolower($this->projectType); + }catch(\Exception $e){ + $this->logger->debug(sprintf( + '%s (branch %s) : file %s not found', + $project->getName(), + $project->getDefaultBranch(), + 'composer.json' + )); + return false; + } + } +}