<commit_before>'use strict';

var scenariosDataStoreFactory = require('./models/scenariosModel'),
	stepsDataStoreFactory = require('./models/stepsModel'),
	coreUtils = require('../core/utils'),
	fs = require('fs'),
	zlib = require('zlib'),

	PASSED = 'passed',
	FAILED = 'failed',
	SKIPPED = 'skipped',

	STATUS_NONE = 'none',
	STATUS_FIX = 'fix',
	STATUS_AUTO_FIX= 'auto-fix',
	STATUS_RECIDIVIST = 'recidivist',
	STATUS_AUTO_RECIDIVIST = 'auto-recidivist',

	LOGGER = new (require('../core/Logger'))('CucumberJSONParser')
;

function CucumberJSONParser(nighlyId, buildId) {
	this.nighlyId = nighlyId;
	this.buildId = buildId;

	this.scenariosModel = scenariosDataStoreFactory(this.nighlyId);
	this.stepsModel = stepsDataStoreFactory(this.nighlyId);
}

CucumberJSONParser.prototype.parse = function(json) {
	return new Promise((resolve, reject) => {

		this.promises = [];
		json.forEach(this._processFeature.bind(this));

		Promise.all(this.promises)
			.then(_ => resolve())
			.catch(_ => reject())
		;
	});
};

CucumberJSONParser.prototype._processTags = function(tags) {
	if(tags === undefined) {
		return [];
	}
	return tags.map(function(item) {
		return item.name;
	});
};

CucumberJSONParser.prototype._processFeature = function(feature, index) {
	try {

		if(!!feature.elements) {
			feature.elements.forEach(this._processScenario.bind(this, feature.uri, this._processTags(feature.tags)));
		} else {
			LOGGER.warn('Feature ' + index + ' doesn\'t have elements');
		}
	} catch (_err) {
		LOGGER.error('Error Processing Feature ', _err.toString() + '\n\t' + _err.stack);
	}
};

CucumberJSONParser.prototype._processScenario = function(featureUri, featureTags, scenario) {
	try {

		if(!!scenario.steps) {
			var me = this;
			var currentExecution = {
				buildId: this.buildId,<commit_msg>DG [] FIX: proper Tags parser<commit_after>'use strict';

var scenariosDataStoreFactory = require('./models/scenariosModel'),
	stepsDataStoreFactory = require('./models/stepsModel'),
	coreUtils = require('../core/utils'),
	fs = require('fs'),
	zlib = require('zlib'),

	PASSED = 'passed',
	FAILED = 'failed',
	SKIPPED = 'skipped',

	STATUS_NONE = 'none',
	STATUS_FIX = 'fix',
	STATUS_AUTO_FIX= 'auto-fix',
	STATUS_RECIDIVIST = 'recidivist',
	STATUS_AUTO_RECIDIVIST = 'auto-recidivist',

	LOGGER = new (require('../core/Logger'))('CucumberJSONParser')
;

function CucumberJSONParser(nighlyId, buildId) {
	this.nighlyId = nighlyId;
	this.buildId = buildId;

	this.scenariosModel = scenariosDataStoreFactory(this.nighlyId);
	this.stepsModel = stepsDataStoreFactory(this.nighlyId);
}

CucumberJSONParser.prototype.parse = function(json) {
	return new Promise((resolve, reject) => {

		this.promises = [];
		json.forEach(this._processFeature.bind(this));

		Promise.all(this.promises)
			.then(_ => resolve())
			.catch(_ => reject())
		;
	});
};

CucumberJSONParser.prototype._processTags = function(tags) {
	if(tags === undefined) {
		return [];
	}
	return tags.map(function(item) {
		if(typeof item === 'string') {
			return item;
		} else if(item.hasOwnProperty('name')) {
			return item.name;
		}
	});
};

CucumberJSONParser.prototype._processFeature = function(feature, index) {
	try {

		if(!!feature.elements) {
			feature.elements.forEach(this._processScenario.bind(this, feature.uri, this._processTags(feature.tags)));
		} else {
			LOGGER.warn('Feature ' + index + ' doesn\'t have elements');
		}
	} catch (_err) {
		LOGGER.error('Error Processing Feature ', _err.toString() + '\n\t' + _err.stack);
	}
};

CucumberJSONParser.prototype._processScenario = function(featureUri, featureTags, scenario) {
	try {

		if(!!scenario.steps) {
			var me = this;
			var currentExecution = {
				buildId: this.buildId,
{'fraction_non_alphanumeric': 0.16122944189808575, 'fraction_numerical': 0.0, 'mean_word_length': 4.787831513260531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '630150', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1271, 'n_words': 210}