diff --git a/Runner.php b/Runner.php index 760d255..39db681 100644 --- a/Runner.php +++ b/Runner.php @@ -15,32 +15,64 @@ public function __construct($config, $server) public function queueDirectory($dir, $prefix = '') { + if(isset($this->config['include_paths'])) { + $this->queueWithIncludePaths(); + } else { + $this->queuePaths($dir, $prefix, $this->config['exclude_paths']); + } + + $this->server->process_work(false); + } + + public function queueWithIncludePaths() { + foreach ($this->config['include_paths'] as $f) { + if ($f !== '.' and $f !== '..') { + + if (is_dir("/code$f")) { + $this->queuePaths("/code$f", "$f/"); + continue; + } + + if (isset($this->config['config']['file_extensions'])) { + $this->filterByExtension($f); + } else { + $this->server->addwork(array("/code/$f")); + } + } + } + } + + public function queuePaths($dir, $prefix = '', $exclusions = []) { $dir = rtrim($dir, '\\/'); foreach (scandir($dir) as $f) { - if (in_array("$prefix$f", $this->config["exclude_paths"])) { + if (in_array("$prefix$f", $exclusions)) { continue; } if ($f !== '.' and $f !== '..') { if (is_dir("$dir/$f")) { - $this->queueDirectory("$dir/$f", "$prefix$f/"); + $this->queuePaths("$dir/$f", "$prefix$f/", $exclusions); continue; } if (isset($this->config['config']['file_extensions'])) { - foreach (explode(",", $this->config['config']['file_extensions']) as $file_extension) { - if (S::create($f)->endsWith("." . $file_extension)) { - $this->server->addwork(array("/code/$prefix$f")); - } - } + $this->filterByExtension($f, $prefix); } else { + $prefix = ltrim($prefix, "\\/"); $this->server->addwork(array("/code/$prefix$f")); } } } + } - $this->server->process_work(false); + public function filterByExtension($f, $prefix = '') { + foreach (explode(",", $this->config['config']['file_extensions']) as $file_extension) { + if (S::create($f)->endsWith("." . $file_extension)) { + $prefix = ltrim($prefix, "\\/"); + $this->server->addwork(array("/code/$prefix$f")); + } + } } public function run($files) diff --git a/circle.yml b/circle.yml index 3024f0a..480c1f8 100644 --- a/circle.yml +++ b/circle.yml @@ -3,21 +3,23 @@ machine: - docker environment: CLOUDSDK_CORE_DISABLE_PROMPTS: 1 - image_name: codeclimate-phpcodesniffer - -dependencies: - pre: - - echo $gcloud_json_key_base64 | sed 's/ //g' | base64 -d > /tmp/gcloud_key.json - - curl https://sdk.cloud.google.com | bash - - gcloud auth activate-service-account $gcloud_account_email --key-file /tmp/gcloud_key.json - - gcloud docker -a + PRIVATE_REGISTRY: us.gcr.io/code_climate test: override: - - docker build -t=$registry_root/$image_name:b$CIRCLE_BUILD_NUM . + - docker build -t=$PRIVATE_REGISTRY/$CIRCLE_PROJECT_REPONAME:b$CIRCLE_BUILD_NUM . deployment: registry: branch: master + owner: codeclimate commands: - - docker push $registry_root/$image_name:b$CIRCLE_BUILD_NUM + - echo $GCLOUD_JSON_KEY_BASE64 | sed 's/ //g' | base64 -d > /tmp/gcloud_key.json + - curl https://sdk.cloud.google.com | bash + - gcloud auth activate-service-account $gcloud_account_email --key-file /tmp/gcloud_key.json + - gcloud docker -a + - docker push $PRIVATE_REGISTRY/$CIRCLE_PROJECT_REPONAME:b$CIRCLE_BUILD_NUM + +notify: + webhooks: + - url: https://cc-slack-proxy.herokuapp.com/circle