<commit_before>var path = require('path');
var inflection = require('./inflection');
var Promise = require('bluebird');
var lpad = require('./util').lpad;
var Class = require('./class');

function formatPath(dir, name) {
  return path.join(dir, name);
}

function formatName(title, date) {
  return formatDate(date) + '-' + formatTitle(title);
}

function formatDate(date) {
  return [
    date.getUTCFullYear(),
    lpad(date.getUTCMonth() + 1, '0', 2),
    lpad(date.getUTCDate(), '0', 2),
    lpad(date.getUTCHours(), '0', 2),
    lpad(date.getUTCMinutes(), '0', 2),
    lpad(date.getUTCSeconds(), '0', 2)
  ].join('');
}

function formatTitle(title) {
  return inflection.dasherize(title);
}

function parseDate(name) {
  var date = new Date();
  var match = name.match(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})-[^\.]+/);
  date.setUTCFullYear(match[1]);
  date.setUTCDate(match[3]);
  date.setUTCMonth(match[2] - 1);
  date.setUTCHours(match[4]);
  date.setUTCMinutes(match[5]);
  date.setUTCSeconds(match[6]);
  return date;
}

function parseTitle(name) {
  var match = name.match(/\d{14}-([^\.]+)/);
  var dashed = match[1];
  return inflection.humanize(dashed, true);
}

var Skeleton = Class.extend({

  init: function(intern) {
    this.internals = intern;
  },

  _up: function() {
    var params = arguments;

    var cb_executed = false;

    return new Promise(function(resolve, reject) {
      var migration,
        r = function( err ) {
          if ( cb_executed === false ) {

            cb_executed = true;

            if( err )
              reject( err );
            else
              resolve();
          }
        };

      params[ params.length++ ] = r;

      migration = require(this.path).up.apply(this, params);

      if( migration === null ) migration = Promise.resolve();
      if( migration instanceof Promise ) {

        migration
        .then(function() {
          if( cb_executed === false ) {

            cb_executed = true;
            resolve();
          }
        }).catch(function(err) {

          if ( cb_executed === false ) {

            cb_executed = true;
            reject( err );
          }
        });
      }
    }.bind(this));
  },

  _down: function() {
    var params = arguments;
    var cb_executed = false;

    return new Promise(function(resolve, reject) {
      var migration,
          r = function( err ) {
            if ( cb_executed === false ) {

              cb_executed = true;

              if( err )
                reject( err );
              else
                resolve();
            }
          };

      params[ params.length++ ] = r;
      migration = require(this.path).down.apply(this, params);

      if( migration === null ) migration = Promise.resolve();
      if( migration instanceof Promise ) {

        migration
        .then(function() {
          if( cb_executed === false ) {

            cb_executed = true;
            resolve();
          }
        }).catch(function(err) {

          if ( cb_executed === false ) {

            cb_executed = true;
            reject( err );
          }
        });
      }
    }.bind(this));
  },

  up: function(db) {
    return this._up(db);
  },

  down: function(db) {
    return this._down(db);
  },

  setup: function() {
    return require(this.path).setup;
  },

  parseName: function(path) {
    var match = path.match(/(\d{14}-[^.]+)(?:\.*?)?/);
    return match[1];
  },

  parseTitle: parseTitle,
  parseDate: parseDate,
  formatTitle: formatTitle,
  formatPath: formatPath,
  formatName: formatName

});

module.exports = Skeleton;
<commit_msg>refactor(migration): Make check for promise more reliable<commit_after>var path = require('path');
var inflection = require('./inflection');
var Promise = require('bluebird');
var lpad = require('./util').lpad;
var Class = require('./class');

function isPromise( probe ) {

  return probe instanceof Promise || ( probe && probe.then &&
    probe.constructor && probe.constructor.name === 'Promise' ); 
}

function formatPath(dir, name) {
  return path.join(dir, name);
}

function formatName(title, date) {
  return formatDate(date) + '-' + formatTitle(title);
}

function formatDate(date) {
  return [
    date.getUTCFullYear(),
    lpad(date.getUTCMonth() + 1, '0', 2),
    lpad(date.getUTCDate(), '0', 2),
    lpad(date.getUTCHours(), '0', 2),
    lpad(date.getUTCMinutes(), '0', 2),
    lpad(date.getUTCSeconds(), '0', 2)
  ].join('');
}

function formatTitle(title) {
  return inflection.dasherize(title);
}

function parseDate(name) {
  var date = new Date();
  var match = name.match(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})-[^\.]+/);
  date.setUTCFullYear(match[1]);
  date.setUTCDate(match[3]);
  date.setUTCMonth(match[2] - 1);
  date.setUTCHours(match[4]);
  date.setUTCMinutes(match[5]);
  date.setUTCSeconds(match[6]);
  return date;
}

function parseTitle(name) {
  var match = name.match(/\d{14}-([^\.]+)/);
  var dashed = match[1];
  return inflection.humanize(dashed, true);
}

var Skeleton = Class.extend({

  init: function(intern) {
    this.internals = intern;
  },

  _up: function() {
    var params = arguments;

    var cb_executed = false;

    return new Promise(function(resolve, reject) {
      var migration,
        r = function( err ) {
          if ( cb_executed === false ) {

            cb_executed = true;

            if( err )
              reject( err );
            else
              resolve();
          }
        };

      params[ params.length++ ] = r;

      migration = require(this.path).up.apply(this, params);

      if( migration === null ) migration = Promise.resolve();
      if( isPromise( migration ) ) {

        migration
        .then(function() {
          if( cb_executed === false ) {

            cb_executed = true;
            resolve();
          }
        }).catch(function(err) {

          if ( cb_executed === false ) {

            cb_executed = true;
            reject( err );
          }
        });
      }
    }.bind(this));
  },

  _down: function() {
    var params = arguments;
    var cb_executed = false;

    return new Promise(function(resolve, reject) {
      var migration,
          r = function( err ) {
            if ( cb_executed === false ) {

              cb_executed = true;

              if( err )
                reject( err );
              else
                resolve();
            }
          };

      params[ params.length++ ] = r;
      migration = require(this.path).down.apply(this, params);

      if( migration === null ) migration = Promise.resolve();
      if( isPromise( migration ) ) {

        migration
        .then(function() {
          if( cb_executed === false ) {

            cb_executed = true;
            resolve();
          }
        }).catch(function(err) {

          if ( cb_executed === false ) {

            cb_executed = true;
            reject( err );
          }
        });
      }
    }.bind(this));
  },

  up: function(db) {
    return this._up(db);
  },

  down: function(db) {
    return this._down(db);
  },

  setup: function() {
    return require(this.path).setup;
  },

  parseName: function(path) {
    var match = path.match(/(\d{14}-[^.]+)(?:\.*?)?/);
    return match[1];
  },

  parseTitle: parseTitle,
  parseDate: parseDate,
  formatTitle: formatTitle,
  formatPath: formatPath,
  formatName: formatName

});

module.exports = Skeleton;

{'fraction_non_alphanumeric': 0.1626554894537588, 'fraction_numerical': 0.008112493239588967, 'mean_word_length': 2.1396434634974533, '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': '2305804', 'n_tokens_mistral': 2413, 'n_tokens_neox': 2343, 'n_words': 494}