From c94d1db15bab064ad79045bd4c93e81a34d38c72 Mon Sep 17 00:00:00 2001 From: Jacek Kubiak Date: Tue, 29 Sep 2015 16:47:02 +0200 Subject: [PATCH 1/2] Modify index.js to support include_paths --- index.js | 74 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index e73b976..a20dc09 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ var printIssue = function(fileName, lineNum, matchedString){ "path": fileName, "lines": { "begin": lineNum, - "end": lineNum + "end": lineNum } } }; @@ -44,7 +44,7 @@ var findFixmes = function(file){ if (results !== ""){ // Parses grep output var lines = results.split("\n"); - + lines.forEach(function(line, index, array){ // grep spits out an extra line that we can ignore if(index < (array.length-1)){ @@ -65,39 +65,65 @@ var findFixmes = function(file){ }) } -var eligibleFile = function(fp, excludePaths){ - return (excludePaths.indexOf(fp.split("/code/")[1]) < 0) && - !fs.lstatSync(fp).isDirectory() && - (excludeExtensions.indexOf(path.extname(fp)) < 0) +// Returns an array of unique array values not included in the other provided array +var diff = function(a1, a2) { + var result = []; + + for (var i = 0; i < a1.length; i++) { + if (a2.indexOf(a1[i]) === -1) { + result.push(a1[i]); + } + + } + return result; } -// Uses glob to traverse code directory and find files to analyze, -// excluding files passed in with by CLI config -var fileWalk = function(excludePaths){ - var analysisFiles = []; - var allFiles = glob.sync("/code/**/**", {}); +// Returns all the file paths in the main directory that match the given pattern +var buildFiles = function(paths) { + var files = []; - allFiles.forEach(function(file, i, a){ - if(eligibleFile(file, excludePaths)){ - analysisFiles.push(file); - } + paths.forEach(function(path, i, a) { + var pattern = "/code/" + path + "**" + files.push.apply(files, glob.sync(pattern, {})); + }); + + return files; +} + +// Filters the directory paths out +var filterFiles = function(files) { + return files.filter(function(file) { + return !fs.lstatSync(file).isDirectory(); }); - - return analysisFiles; +} + +// Returns file paths based on the exclude_paths values in config file +var buildFilesWithExclusions = function(exclusions) { + var allFiles = glob.sync("/code/**/**", {}); + var excludedFiles = buildFiles(exclusions); + + return diff(allFiles, excludedFiles); +} + +// Returns file paths based on the include_paths values in config file +var buildFilesWithInclusions = function(inclusions) { + return buildFiles(inclusions); } FixMe.prototype.runEngine = function(){ - // Check for existence of config.json, parse exclude paths if it exists + var analysisFiles = [] + if (fs.existsSync("/config.json")) { var engineConfig = JSON.parse(fs.readFileSync("/config.json")); - var excludePaths = engineConfig.exclude_paths; - } else { - var excludePaths = []; - } - // Walk /code/ path and find files to analyze - var analysisFiles = fileWalk(excludePaths); + if (engineConfig.hasOwnProperty("include_paths")) { + analysisFiles = buildFilesWithInclusions(engineConfig.include_paths); + } else if (engineConfig.hasOwnProperty("exclude_paths")) { + analysisFiles = buildFilesWithExclusions(engineConfig.exclude_paths); + } + } + analysisFiles = filterFiles(analysisFiles); // Execute main loop and find fixmes in valid files analysisFiles.forEach(function(f, i, a){ findFixmes(f); From b84763b8d190ced56d1dddfb8df805c12c161343 Mon Sep 17 00:00:00 2001 From: ABaldwinHunter Date: Thu, 8 Oct 2015 10:43:02 -0400 Subject: [PATCH 2/2] update registry reference for circle This change should allow tests to pass on PRs from forks And fix https://github.com/codeclimate/codeclimate-fixme/pull/8 --- circle.yml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/circle.yml b/circle.yml index c51658a..012fc78 100644 --- a/circle.yml +++ b/circle.yml @@ -3,21 +3,23 @@ machine: - docker environment: CLOUDSDK_CORE_DISABLE_PROMPTS: 1 - image_name: codeclimate-fixme - -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 --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