<commit_before>var settings = require('../settings');
var utils = require('../utils');
var _ = require('underscore');
var path = require('path');

var make_defaults = utils.make_class({
  init: function(){
    var self = this;
    self.tags =  [];
    self.links =  {};
    self.environments =  [];
    self.metadata =  {};
    self.related_apis =  {};
    self.dependent_services =  [];
    self.events =  [];
    self.kpi_spec =  '';

    self.errors =  [];
    // By convention, middlewares will populate this fields,
    // if the related_apis exist, with {'error': X, 'data': X}
    self.pager_duty =  null;
    self.version_one =  null;
    self.github =  null;
    self.new_relic =  null;
    self.dreadnot =  null;
  }
});

/**
 * If req.params.project, assigns req.devops to loaded devops object
 */
module.exports = function load_devops(devops_directory) {
  var extcreds;
  var devops = {};

  if (!devops_directory){
    devops_directory = path.join(__dirname, '..', '..', settings.saved_crawls_path);
  }
  _.each(settings.devopsjson_uris, function(uri, project_name){

    var devops_path = path.join(devops_directory, project_name);

    var api_name;
    var api_obj;
    var _devops;

    _devops = utils.load_devops(devops_path);

    _devops.project = project_name;

    // fill in missing optional fields
    _.defaults(_devops, new make_defaults());

    // fill in __external__ related api creds from local settings
    // if they exist

    if (settings.external_creds && settings.external_creds[project_name]) {
      extcreds = settings.external_creds[project_name];
      for (api_name in _devops.related_apis){
        if (!extcreds[api_name]){
          continue;
        }

        api_obj = _devops.related_apis[api_name];
        _.defaults(api_obj, extcreds[api_name]);

      }
    }
    devops[project_name] = _devops;
  });
  devops.dir = devops_directory;
  return devops;
};<commit_msg>Take settings.js and stomp over anything that matches in devops.json.<commit_after>var settings = require('../settings');
var utils = require('../utils');
var _ = require('underscore');
var path = require('path');

var make_defaults = utils.make_class({
  init: function(){
    var self = this;
    self.tags =  [];
    self.links =  {};
    self.environments =  [];
    self.metadata =  {};
    self.related_apis =  {};
    self.dependent_services =  [];
    self.events =  [];
    self.kpi_spec =  '';

    self.errors =  [];
    // By convention, middlewares will populate this fields,
    // if the related_apis exist, with {'error': X, 'data': X}
    self.pager_duty =  null;
    self.version_one =  null;
    self.github =  null;
    self.new_relic =  null;
    self.dreadnot =  null;
  }
});

/**
 * If req.params.project, assigns req.devops to loaded devops object
 */
module.exports = function load_devops(devops_directory) {
  var extcreds;
  var devops = {};

  if (!devops_directory){
    devops_directory = path.join(__dirname, '..', '..', settings.saved_crawls_path);
  }
  _.each(settings.devopsjson_uris, function(uri, project_name){

    var devops_path = path.join(devops_directory, project_name);

    var api_name;
    var api_obj;
    var _devops;

    _devops = utils.load_devops(devops_path);

    _devops.project = project_name;

    // fill in missing optional fields
    _.defaults(_devops, new make_defaults());

    // fill in __external__ related api creds from local settings
    // if they exist

    if (settings.external_creds && settings.external_creds[project_name]) {
      extcreds = settings.external_creds[project_name];
      for (api_name in _devops.related_apis){
        if (!extcreds[api_name]){
          continue;
        }

        api_obj = _devops.related_apis[api_name];
        _.extend(api_obj, extcreds[api_name]);

      }
    }
    devops[project_name] = _devops;
  });
  devops.dir = devops_directory;
  return devops;
};
{'fraction_non_alphanumeric': 0.13205128205128205, 'fraction_numerical': 0.0, 'mean_word_length': 2.9846782431052095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5794350', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1291, 'n_words': 275}