From ae26d690c97341ff33b1430a006e846fb71667e0 Mon Sep 17 00:00:00 2001 From: MBorne Date: Sat, 24 Nov 2018 19:42:29 +0100 Subject: [PATCH] Add getDescription() to ProjectFilterInterface to improve logs (refs #24) --- README.md | 2 +- src/MBO/RemoteGit/Filter/FilterCollection.php | 32 ++++++++++++++++--- .../Filter/GitlabNamespaceFilter.php | 7 ++++ .../RemoteGit/Filter/IgnoreRegexpFilter.php | 7 ++++ .../Filter/IncludeIfHasFileFilter.php | 8 +++++ .../RemoteGit/Filter/ProjectTypeFilter.php | 11 +++++++ src/MBO/RemoteGit/ProjectFilterInterface.php | 7 ++++ 7 files changed, 69 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cdbe9be..5d26204 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ bin/satis-gitlab gitlab-to-config https://gitlab.com $SATIS_GITLAB_TOKEN -vv --u Experimental support for github allows to perform : ```bash -bin/satis-gitlab gitlab-to-config https://github.com $GITHUB_TOKEN --orgs=symfony --users=mborne +bin/satis-gitlab gitlab-to-config https://github.com $SATIS_GITHUB_TOKEN --orgs=symfony --users=mborne bin/satis-gitlab build --skip-errors satis.json web ``` diff --git a/src/MBO/RemoteGit/Filter/FilterCollection.php b/src/MBO/RemoteGit/Filter/FilterCollection.php index 97c3496..3ca6d15 100644 --- a/src/MBO/RemoteGit/Filter/FilterCollection.php +++ b/src/MBO/RemoteGit/Filter/FilterCollection.php @@ -41,6 +41,17 @@ public function addFilter(ProjectFilterInterface $filter){ $this->filters[] = $filter; } + /** + * {@inheritDoc} + */ + public function getDescription(){ + $parts = array(); + foreach ( $this->filters as $filter ){ + $parts[] = ' - '.$filter->getDescription(); + } + return implode(PHP_EOL,$parts); + } + /** * {@inheritDoc} */ @@ -48,18 +59,31 @@ public function isAccepted(ProjectInterface $project){ foreach ( $this->filters as $filter ){ if ( ! $filter->isAccepted($project) ){ $this->logger->info(sprintf( - "[%s]Ignoring project %s", - get_class($filter), - $project->getName() + "[%s]Ignoring project %s (%s)", + $this->getFilterName($filter), + $project->getName(), + $filter->getDescription() )); return false; } } - $this->logger->info(sprintf( + $this->logger->debug(sprintf( "[FilterCollection]keep project %s", $project->getName() )); return true; } + + /** + * Get filter name + * + * @param ProjectFilterInterface $filter + * @return string + */ + private function getFilterName(ProjectFilterInterface $filter){ + $clazz = get_class($filter); + $parts = explode('\\',$clazz); + return $parts[count($parts)-1]; + } } diff --git a/src/MBO/RemoteGit/Filter/GitlabNamespaceFilter.php b/src/MBO/RemoteGit/Filter/GitlabNamespaceFilter.php index a45c914..90053a0 100644 --- a/src/MBO/RemoteGit/Filter/GitlabNamespaceFilter.php +++ b/src/MBO/RemoteGit/Filter/GitlabNamespaceFilter.php @@ -40,6 +40,13 @@ public function __construct($groups) $this->groups = explode(',',strtolower($groups)); } + /** + * {@inheritDoc} + */ + public function getDescription(){ + return "gitlab namespace should be one of [".implode(', ',$this->groups)."]"; + } + /** * {@inheritDoc} */ diff --git a/src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php b/src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php index 2770275..0c27434 100644 --- a/src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php +++ b/src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php @@ -21,6 +21,13 @@ public function __construct($ignoreRegexp) $this->ignoreRegexp = $ignoreRegexp; } + /** + * {@inheritDoc} + */ + public function getDescription(){ + return "project name should not match /".$this->ignoreRegexp+"/"; + } + /** * {@inheritDoc} */ diff --git a/src/MBO/RemoteGit/Filter/IncludeIfHasFileFilter.php b/src/MBO/RemoteGit/Filter/IncludeIfHasFileFilter.php index c97b507..bca00d2 100644 --- a/src/MBO/RemoteGit/Filter/IncludeIfHasFileFilter.php +++ b/src/MBO/RemoteGit/Filter/IncludeIfHasFileFilter.php @@ -35,6 +35,14 @@ public function __construct( $this->logger = $logger; } + /** + * {@inheritDoc} + */ + public function getDescription(){ + return sprintf("File '%s' should exist in default branch",$this->filePath); + } + + /** * {@inheritDoc} */ diff --git a/src/MBO/RemoteGit/Filter/ProjectTypeFilter.php b/src/MBO/RemoteGit/Filter/ProjectTypeFilter.php index 08cfbe1..32a1417 100644 --- a/src/MBO/RemoteGit/Filter/ProjectTypeFilter.php +++ b/src/MBO/RemoteGit/Filter/ProjectTypeFilter.php @@ -43,6 +43,17 @@ public function __construct($type, GitClientInterface $gitClient, LoggerInterfac $this->logger = $logger; } + /** + * {@inheritDoc} + */ + public function getDescription(){ + return sprintf( + "composer.json should exists and type should be '%s'", + $this->projectType + ); + } + + /** * {@inheritDoc} */ diff --git a/src/MBO/RemoteGit/ProjectFilterInterface.php b/src/MBO/RemoteGit/ProjectFilterInterface.php index a8f73c7..99193e4 100644 --- a/src/MBO/RemoteGit/ProjectFilterInterface.php +++ b/src/MBO/RemoteGit/ProjectFilterInterface.php @@ -7,6 +7,13 @@ */ interface ProjectFilterInterface { + /** + * Get filter description (ex : "Project should contains a composer.json file") + * + * @return string + */ + public function getDescription(); + /** * Returns true if the project should be included in satis configuration *