<commit_before>'use strict';

var conf = require('./config');
var logger = require('./logger');
var ledstrip = require('./ledstrip');
var MSG_REGEX = /^Build\s(\w*)\:\s(.*)\s(\#\d*)$/;

var localStorage;

if (typeof localStorage === 'undefined' || localStorage === null) {
  var LocalStorage = require('node-localstorage').LocalStorage;
  localStorage = new LocalStorage('./scratch');
}

function execRegex(msg) {
  var groups = MSG_REGEX.exec(msg);

  if (groups) {
    var pipelines = conf.get('pipelines'),
      buildPipelineStage = groups[2].split('-'),
      config = pipelines
        .filter(function (el) {
          return el.name === buildPipelineStage[0].trim();
        })[0].stages
        .filter(function (el) {
          return el.name === buildPipelineStage[1].trim();
        })[0];

    return {
      pipeline: buildPipelineStage[0].trim(),
      stage: buildPipelineStage[1].trim(),
      status: groups[1].toLowerCase(),
      buildNum: groups[3],
      config: config
    }
  }
}

module.exports.translate = function (msg) {
  var building = conf.get('leds:building'),
    build = execRegex(msg);

  logger.log('info', 'Translating msg [%s] to build config [%j]', msg, build);

  if (build) {

    var intervalId = localStorage.getItem(build.stage)

    if (intervalId) {
      clearInterval(intervalId);
      localStorage.removeItem(build.stage);
      ledstrip.disconnect(conf.get('leds:colours:' + build.status));
    }

    if (build.status.indexOf('started') > -1) {
      ledstrip.connect(build.config.offset, build.config.length);
      intervalId = ledstrip.animate(building);
      localStorage.setItem(build.stage, intervalId);
    }
  }

}<commit_msg>Fixing 'undefined' stages when searching for pipeline / stage<commit_after>'use strict';

var conf = require('./config');
var logger = require('./logger');
var ledstrip = require('./ledstrip');
var MSG_REGEX = /^Build\s(\w*)\:\s(.*)\s(\#\d*)$/;

var localStorage;

if (typeof localStorage === 'undefined' || localStorage === null) {
  var LocalStorage = require('node-localstorage').LocalStorage;
  localStorage = new LocalStorage('./scratch');
}

function execRegex(msg) {
  var groups = MSG_REGEX.exec(msg);

  if (groups) {
    var pipelines = conf.get('pipelines'),
      buildPipelineStage = groups[2].split('-'),
      config;

    var pipeline = pipelines
      .filter(function (el) {
        return el.name === buildPipelineStage[0].trim();
      })[0];

    if (pipeline) {
      config = pipeline.stages
        .filter(function (el) {
          return el.name === buildPipelineStage[1].trim();
        })[0]
    }

    if (!config) {
      return {};
    }

    return {
      pipeline: buildPipelineStage[0].trim(),
      stage: buildPipelineStage[1].trim(),
      status: groups[1].toLowerCase(),
      buildNum: groups[3],
      config: config
    }
  }
}

module.exports.translate = function (msg) {
  var building = conf.get('leds:building'),
    build = execRegex(msg);

  logger.log('info', 'Translating msg [%s] to build config [%j]', msg, build);

  if (build) {

    var intervalId = localStorage.getItem(build.stage)

    if (intervalId) {
      clearInterval(intervalId);
      localStorage.removeItem(build.stage);
      ledstrip.disconnect(conf.get('leds:colours:' + build.status));
    }

    if (build.status.indexOf('started') > -1) {
      ledstrip.connect(build.config.offset, build.config.length);
      intervalId = ledstrip.animate(building);
      localStorage.setItem(build.stage, intervalId);
    }

  } else {
    logger.log('info', 'Could not process queue message, possible pipeline not found.');
  }

}
{'fraction_non_alphanumeric': 0.16639118457300275, 'fraction_numerical': 0.005509641873278237, 'mean_word_length': 3.19284064665127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2710224', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1124, 'n_words': 233}