<commit_before>
var yaml = require('yamljs');
var _ = require('underscore');


var HookDefaults = {
    assignee: null,
    status: null,
};


function normalizeProjectConfig(name, cfg, globals) {
    var open = _.defaults(cfg.open || {}, globals.open || {}, HookDefaults);
    var close = _.defaults(cfg.close || {}, globals.close || {}, HookDefaults);
    var merge = _.defaults(cfg.merge || {}, globals.merge || {}, HookDefaults);

    var obj = {
        name: name,
        open: open,
        merge: merge,
        close: close
    };

    return obj;
}

function getBool(val) {
    if(_.isUndefined(val)) {
        return false;
    } else if(_.isString(val)) {
        return _.indexOf(
            ['y', 'yes', 't', 'true', '1', 'on'],
            val.toLowerCase()
        ) >= 0;
    } else if(_.isNumber(val)) {
        return val > 0;
    }

    return false;
}


function loadConfig(path) {
    var data = yaml.load(path);

    var config = {
        redmine: data.redmine,
        projects: []
    };

    config.redmine.impersonate = getBool(config.redmine.impersonate);

    _.each(data.projects, function(name) {
        var projData = data[name];
        config.projects.push(normalizeProjectConfig(name, projData, data.redmine));
    });

    return config;
}


module.exports = loadConfig;




<commit_msg>similified and fixed configuration design<commit_after>
var yaml = require('yamljs');
var _ = require('underscore');
var util = require('util');

function getBool(val) {
  if(!_.isString(val)) {
    return val;
  }

  var t = val.toLowerCase();
  return ['t', 'true', 'y', 'yes', 'on', '1'].indexOf(t) >= 0;
}

function MrIssueConfig() {
  var data = yaml.load("./config.yml");
  var self = this;

  this.redmine = data.redmine;
  this.redmine.impersonate = getBool(data.redmine.impersonate);
  this.projects = [];

  var globalActions = data.redmine.actions || {};

  _.each(data.projects, function(name) {
    var project = data[name];

    project.name = name;

    for(var actionName in globalActions) {
      project.actions[actionName] = _.defaults({}, project.actions[actionName], globalActions[actionName]);
    }

    /*
    for(var actionName in projData.actions) {
      console.log("Globals: " + util.inspect(globalActions[actionName]));
      projData.actions[actionName] = _.defaults({}, projData.actions[actionName], globalActions[actionName]);
    }
    */

    self.projects.push(project);
  });
}

MrIssueConfig.prototype.getUserLookups = function() {
  var lookups = [];

  _.each(this.projects, function(project) {
    //_.each(project.actions, function(actionName) {
    for(var actionName in project.actions) {
      var actions = project.actions[actionName];
      if(actions.assignee) {
        console.log("Lookup: " + actions.assignee);
        lookups.push(actions.assignee);
      }
    }
  });

  return _.uniq(lookups);
};

MrIssueConfig.prototype.getIssueStatusLookups = function() {
  var lookups = [];

  _.each(this.projects, function(project) {
    for(var actionName in project.actions) {
      var actions = project.actions[actionName];
      if(actions.status) {
        lookups.push(actions.status);
      }
    }
  });

  return _.uniq(lookups);
}

MrIssueConfig.prototype.getProjectConfig = function(url) {
  var name = url.substring(1);
  for(var i in this.projects) {
    var proj = this.projects[i];
    if(proj.name == name) {
      return proj;
    }
  }
  return null;
};

module.exports = MrIssueConfig;

{'fraction_non_alphanumeric': 0.15406726070709975, 'fraction_numerical': 0.0017246335153779822, 'mean_word_length': 2.9726027397260273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '6105390', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1106, 'n_words': 220}