<commit_before>'use strict';

var request = require('request');
var constants = require('./constants');

var ALLOWED_CREDENTIALS = [
  { name: 'userAuthKey', type: 'string' },
  { name: 'app', type: 'object', requiredFields: ['appAuthKey', 'appId'] }
];

/**
 * make a basic request
 * @param url
 * @param apiKey
 * @param method :  [ GET, POST, PUT ...]
 * @param body
 * @param callback  (err, httpResponse, body)
 */
var basicRequest = function (url, apiKey, method, body, callback) {
  var options = {
    url: url,
    method: method
  };
  if (apiKey) {
    options.headers = {
      'Content-Type': 'application/json; charset=utf-8',
      'Authorization': 'Basic ' + apiKey
    }
  }
  if (body) {
    options.body = body;
    options.json = true;
  }

  return new Promise(function (resolve, reject) {
    request(options, function (err, httpResponse, data) {
      if (err) {
        callback && callback(err, httpResponse, data);
        return reject(err);
      }

      callback && callback(err, httpResponse, data);
      return resolve({ httpResponse: httpResponse, data: data });
    });
  });
};
<commit_msg>Fix returning promise when callback is given<commit_after>'use strict';

var request = require('request');
var constants = require('./constants');

var ALLOWED_CREDENTIALS = [
  { name: 'userAuthKey', type: 'string' },
  { name: 'app', type: 'object', requiredFields: ['appAuthKey', 'appId'] }
];

/**
 * make a basic request
 * @param url
 * @param apiKey
 * @param method :  [ GET, POST, PUT ...]
 * @param body
 * @param callback  (err, httpResponse, body)
 */
var basicRequest = function (url, apiKey, method, body, callback) {
  var options = {
    url: url,
    method: method
  };
  if (apiKey) {
    options.headers = {
      'Content-Type': 'application/json; charset=utf-8',
      'Authorization': 'Basic ' + apiKey
    }
  }
  if (body) {
    options.body = body;
    options.json = true;
  }

  return new Promise(function (resolve, reject) {
    request(options, function (err, httpResponse, data) {
      if (err) {
        return callback ? callback(err, httpResponse, data) : reject(err);
      }
      return callback ? callback(err, httpResponse, data) : resolve({ httpResponse: httpResponse, data: data });
    });
  });
};

{'fraction_non_alphanumeric': 0.1568281938325991, 'fraction_numerical': 0.000881057268722467, 'mean_word_length': 3.1746323529411766, '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': '3772754', 'n_tokens_mistral': 718, 'n_tokens_neox': 714, 'n_words': 202}