Skip to content

Commit

Permalink
Add getDescription() to ProjectFilterInterface to improve logs (refs #24
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mborne committed Nov 24, 2018
1 parent 17112c6 commit ae26d69
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
32 changes: 28 additions & 4 deletions src/MBO/RemoteGit/Filter/FilterCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,49 @@ 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}
*/
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];
}
}

7 changes: 7 additions & 0 deletions src/MBO/RemoteGit/Filter/GitlabNamespaceFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
7 changes: 7 additions & 0 deletions src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public function __construct($ignoreRegexp)
$this->ignoreRegexp = $ignoreRegexp;
}

/**
* {@inheritDoc}
*/
public function getDescription(){
return "project name should not match /".$this->ignoreRegexp+"/";
}

/**
* {@inheritDoc}
*/
Expand Down
8 changes: 8 additions & 0 deletions src/MBO/RemoteGit/Filter/IncludeIfHasFileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
11 changes: 11 additions & 0 deletions src/MBO/RemoteGit/Filter/ProjectTypeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
7 changes: 7 additions & 0 deletions src/MBO/RemoteGit/ProjectFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit ae26d69

Please sign in to comment.