From fec9641bdc65392f2f5cd3dbde5ed866056d08d6 Mon Sep 17 00:00:00 2001 From: Rich Gerdes Date: Tue, 23 Oct 2018 17:04:41 -0400 Subject: [PATCH 1/2] Add gitlab group/namespace filter. --- .../Command/GitlabToConfigCommand.php | 8 +++ .../Filter/GitlabNamespaceFilter.php | 64 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/MBO/SatisGitlab/Filter/GitlabNamespaceFilter.php diff --git a/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php b/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php index a8c24ce..1e4a36a 100644 --- a/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php +++ b/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php @@ -20,6 +20,7 @@ use MBO\SatisGitlab\Git\GitlabProject; use MBO\SatisGitlab\Filter\FilterCollection; +use MBO\SatisGitlab\Filter\GitlabNamespaceFilter; use MBO\SatisGitlab\Filter\IgnoreRegexpFilter; use MBO\SatisGitlab\Filter\IncludeIfHasFileFilter; use MBO\SatisGitlab\Filter\ProjectTypeFilter; @@ -63,6 +64,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) + ->addOption('gitlab-groups',null,InputOption::VALUE_REQUIRED, 'include in satis config if gitlab project namespace is in the list, for ex : "2,Diaspora"', null) /* * satis config generation options */ @@ -131,6 +133,12 @@ protected function execute(InputInterface $input, OutputInterface $output) { $logger )); } + /* project-type option */ + if ( ! empty($input->getOption('gitlab-groups')) ){ + $filterCollection->addFilter(new GitlabNamespaceFilter( + $input->getOption('gitlab-groups') + )); + } /* * Create configuration builder diff --git a/src/MBO/SatisGitlab/Filter/GitlabNamespaceFilter.php b/src/MBO/SatisGitlab/Filter/GitlabNamespaceFilter.php new file mode 100644 index 0000000..c8eefb7 --- /dev/null +++ b/src/MBO/SatisGitlab/Filter/GitlabNamespaceFilter.php @@ -0,0 +1,64 @@ +groups = explode(',',strtolower($groups)); + } + + /** + * {@inheritDoc} + */ + public function isAccepted(ProjectInterface $project) + { + $project_info = $project->getRawMetadata(); + if (isset($project_info['namespace'])) { + + // Extra data from namespace to patch on. + $valid_keys = [ + 'name' => 'name', + 'id' => 'id', + ]; + $namespace_info = array_intersect_key($project_info['namespace'], $valid_keys); + $namespace_info = array_map('strtolower', $namespace_info); + + if (!empty($namespace_info) && !empty(array_intersect($namespace_info, $this->groups))) { + // Accept any package with a permitted namespace name or id. + return TRUE; + } + } + return FALSE; + } +} From a02f074f0568d7305d78f9136ec2e346da390e45 Mon Sep 17 00:00:00 2001 From: Rich Gerdes Date: Tue, 23 Oct 2018 17:07:37 -0400 Subject: [PATCH 2/2] rename arguement to match command name. --- src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php b/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php index 1e4a36a..03c3c01 100644 --- a/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php +++ b/src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php @@ -64,7 +64,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) - ->addOption('gitlab-groups',null,InputOption::VALUE_REQUIRED, 'include in satis config if gitlab project namespace is in the list, for ex : "2,Diaspora"', null) + ->addOption('gitlab-namespace',null,InputOption::VALUE_REQUIRED, 'include in satis config if gitlab project namespace is in the list, for ex : "2,Diaspora"', null) /* * satis config generation options */ @@ -134,9 +134,9 @@ protected function execute(InputInterface $input, OutputInterface $output) { )); } /* project-type option */ - if ( ! empty($input->getOption('gitlab-groups')) ){ + if ( ! empty($input->getOption('gitlab-namespace')) ){ $filterCollection->addFilter(new GitlabNamespaceFilter( - $input->getOption('gitlab-groups') + $input->getOption('gitlab-namespace') )); }