Skip to content

Commit

Permalink
organize RemoteGit to highlight interfaces (refs #24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mborne committed Nov 24, 2018
1 parent 3b9f5e9 commit 17112c6
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 57 deletions.
4 changes: 4 additions & 0 deletions src/MBO/RemoteGit/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use Psr\Log\LoggerInterface;
use \GuzzleHttp\Client as GuzzleHttpClient;

use MBO\RemoteGit\Github\GithubClient;
use MBO\RemoteGit\Gitlab\GitlabClient;


/**
* Helper to create clients
*/
Expand Down
2 changes: 2 additions & 0 deletions src/MBO/RemoteGit/Filter/FilterCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\ProjectFilterInterface;

/**
* Compose a list of filter to simplify command line integration
Expand Down
4 changes: 3 additions & 1 deletion src/MBO/RemoteGit/Filter/GitlabNamespaceFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace MBO\RemoteGit\Filter;

use Psr\Log\LoggerInterface;

use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\ProjectFilterInterface;
use MBO\RemoteGit\ClientInterface as GitClientInterface;
use Psr\Log\LoggerInterface;

/**
* Filter projects based on GitLab project namespace name or id.
Expand Down
1 change: 1 addition & 0 deletions src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MBO\RemoteGit\Filter;

use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\ProjectFilterInterface;

/**
* Ignore project according to a regular expression
Expand Down
7 changes: 4 additions & 3 deletions src/MBO/RemoteGit/Filter/IncludeIfHasFileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace MBO\RemoteGit\Filter;

use Psr\Log\LoggerInterface;

use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\ProjectFilterInterface;
use MBO\RemoteGit\ClientInterface as GitClientInterface;
use Psr\Log\LoggerInterface;


/**
* Accept projects if git contains a given file
*
* TODO remove (done at git listing level)
*/
class IncludeIfHasFileFilter implements ProjectFilterInterface {

Expand Down
5 changes: 4 additions & 1 deletion src/MBO/RemoteGit/Filter/ProjectTypeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace MBO\RemoteGit\Filter;

use Psr\Log\LoggerInterface;

use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\ProjectFilterInterface;
use MBO\RemoteGit\ClientInterface as GitClientInterface;
use Psr\Log\LoggerInterface;


/**
* Ignore project according to their type
Expand Down
55 changes: 28 additions & 27 deletions src/MBO/RemoteGit/FindOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ class FindOptions {
private $users = array();

/**
* Filters not appliable throw API usage
* Additional filter that can't be implemented throw
* project listing API parameters
*
* @var FilterCollection
* @var ProjectFilterInterface
*/
private $filterCollection ;
private $filter ;

public function __construct(){
$this->filterCollection = new FilterCollection();
$this->filter = new FilterCollection();
}

/**
Expand Down Expand Up @@ -78,75 +79,75 @@ public function setSearch(string $search)


/**
* Get filters not appliable throw API usage
* Get filter according to organizations
*
* @return FilterCollection
* @return string[]
*/
public function getFilterCollection()
public function getOrganizations()
{
return $this->filterCollection;
return $this->organizations;
}

/**
* Set filters not appliable throw API usage
* Set filter according to organizations
*
* @param FilterCollection $filterCollection Filters not appliable throw API usage
* @param string[] $organizations Filter according to organizations
*
* @return self
*/
public function setFilterCollection(FilterCollection $filterCollection)
public function setOrganizations(array $organizations)
{
$this->filterCollection = $filterCollection;
$this->organizations = $organizations;

return $this;
}


/**
* Get filter according to organizations
* Get filter according to user names
*
* @return string[]
*/
public function getOrganizations()
public function getUsers()
{
return $this->organizations;
return $this->users;
}

/**
* Set filter according to organizations
* Set filter according to user names
*
* @param string[] $organizations Filter according to organizations
* @param string[] $users Filter according to user names
*
* @return self
*/
public function setOrganizations(array $organizations)
public function setUsers(array $users)
{
$this->organizations = $organizations;
$this->users = $users;

return $this;
}


/**
* Get filter according to user names
* Get project listing API parameters
*
* @return string[]
* @return ProjectFilterInterface
*/
public function getUsers()
public function getFilter()
{
return $this->users;
return $this->filter;
}

/**
* Set filter according to user names
* Set project listing API parameters
*
* @param string[] $users Filter according to user names
* @param ProjectFilterInterface $filter project listing API parameters
*
* @return self
*/
public function setUsers(array $users)
public function setFilter(ProjectFilterInterface $filter)
{
$this->users = $users;
$this->filter = $filter;

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

namespace MBO\RemoteGit;
namespace MBO\RemoteGit\Github;

use Psr\Log\LoggerInterface;
use \GuzzleHttp\Client as GuzzleHttpClient;

use MBO\RemoteGit\Filter\ProjectFilterInterface;
use MBO\RemoteGit\ClientInterface;
use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\FindOptions;
use MBO\RemoteGit\ProjectFilterInterface;


/**
* Client implementation for github
Expand Down Expand Up @@ -56,13 +60,13 @@ public function find(FindOptions $options){
foreach ( $options->getUsers() as $user ){
$result = array_merge($result,$this->findByUser(
$user,
$options->getFilterCollection()
$options->getFilter()
));
}
foreach ( $options->getOrganizations() as $org ){
$result = array_merge($result,$this->findByOrg(
$org,
$options->getFilterCollection()
$options->getFilter()
));
}
return $result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace MBO\RemoteGit;
namespace MBO\RemoteGit\Github;

use MBO\RemoteGit\ProjectInterface;

/**
* Project implementation for github
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

namespace MBO\RemoteGit;
namespace MBO\RemoteGit\Gitlab;

use \GuzzleHttp\Client as GuzzleHttpClient;
use Psr\Log\LoggerInterface;
use \GuzzleHttp\Client as GuzzleHttpClient;

use MBO\RemoteGit\ClientInterface;
use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\FindOptions;
use MBO\RemoteGit\ProjectFilterInterface;

use MBO\RemoteGit\Filter\ProjectFilterInterface;

/**
* Find gitlab projects
Expand Down Expand Up @@ -57,13 +61,13 @@ public function find(FindOptions $options){
foreach ( $options->getUsers() as $user ){
$result = array_merge($result,$this->findByUser(
$user,
$options->getFilterCollection()
$options->getFilter()
));
}
foreach ( $options->getOrganizations() as $org ){
$result = array_merge($result,$this->findByGroup(
$org,
$options->getFilterCollection()
$options->getFilter()
));
}
return $result;
Expand Down Expand Up @@ -113,7 +117,7 @@ protected function findBySearch(FindOptions $options){
return $this->fetchAllPages(
$path,
$params,
$options->getFilterCollection()
$options->getFilter()
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace MBO\RemoteGit;
namespace MBO\RemoteGit\Gitlab;

use MBO\RemoteGit\ProjectInterface;

/**
* Common project properties between different git project host (gitlab, github, etc.)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php

namespace MBO\RemoteGit\Filter;

use MBO\RemoteGit\ProjectInterface;

namespace MBO\RemoteGit;

/**
* Test if a project should be included in satis config (regexp, )
Expand Down
5 changes: 2 additions & 3 deletions src/MBO/SatisGitlab/Command/GitlabToConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ protected function configure() {
->addArgument('gitlab-token')

/*
* Project listing options (git level)
* Project listing options (hosted git api level)
*/
->addOption('orgs', 'o', InputOption::VALUE_REQUIRED, 'Find projects according to given organization names')
->addOption('users', 'u', InputOption::VALUE_REQUIRED, 'Find projects according to given user names')

->addOption('projectFilter', 'p', InputOption::VALUE_OPTIONAL, 'filter for projects (deprecated : see organization and users)', null)

/*
Expand Down Expand Up @@ -134,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
* Create project filters according to input arguments
*/
$filterCollection = new FilterCollection($logger);
$findOptions->setFilterCollection($filterCollection);
$findOptions->setFilter($filterCollection);

/* ignore if 'composer.json' is not available */
$filterCollection->addFilter(new IncludeIfHasFileFilter(
Expand Down
4 changes: 2 additions & 2 deletions tests/RemoteGit/Filter/FilterCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Psr\Log\NullLogger;

use MBO\RemoteGit\Filter\FilterCollection;
use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\Filter\ProjectFilterInterface;
use MBO\RemoteGit\ProjectFilterInterface;
use MBO\RemoteGit\Filter\FilterCollection;

/**
* Test FilterCollection
Expand Down
3 changes: 2 additions & 1 deletion tests/RemoteGit/Filter/IgnoreRegexpFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use Symfony\Component\Console\Tester\CommandTester;

use MBO\RemoteGit\Filter\IgnoreRegexpFilter;
use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\Filter\IgnoreRegexpFilter;


/**
* Test IgnoreRegexpFilter
Expand Down
6 changes: 4 additions & 2 deletions tests/RemoteGit/GithubClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use Psr\Log\NullLogger;
use MBO\RemoteGit\ClientOptions;
use MBO\RemoteGit\ClientFactory;
use MBO\RemoteGit\GithubClient;
use MBO\RemoteGit\GithubProject;
use MBO\RemoteGit\FindOptions;

use MBO\RemoteGit\Github\GithubClient;
use MBO\RemoteGit\Github\GithubProject;


class GithubClientTest extends TestCase {

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/RemoteGit/GitlabClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use MBO\SatisGitlab\Tests\TestCase;

use GuzzleHttp\Client as GuzzleHttpClient;
use MBO\RemoteGit\GitlabClient;

use Psr\Log\NullLogger;
use MBO\RemoteGit\ClientOptions;
use MBO\RemoteGit\ClientFactory;
use MBO\RemoteGit\FindOptions;

use MBO\RemoteGit\Gitlab\GitlabClient;
use MBO\RemoteGit\Gitlab\GitlabProject;

class GitlabClientTest extends TestCase {

Expand Down

0 comments on commit 17112c6

Please sign in to comment.