<commit_before>'use strict';

var CoreObject = require('core-object');
var jwt        = require('jwt-simple');
var RSVP       = require('rsvp');
var request    = require('superagent');
var fs         = require('fs');
var readFile   = RSVP.denodeify(fs.readFile);

module.exports = CoreObject.extend({
  init: function(config) {
    this.deployHost = config.deployHost;
    this.appKey     = config.appKey;
    this.userKey    = config.userKey;
    this.userSecret = config.userSecret;
  },

  uploadBuild: function(filePath, revision, commitDetails) {
    var url = this._buildUrl([revision]);
    var token = this._token();
    return this._readFileContents(filePath).then(function(body) {
      return new RSVP.Promise(function(resolve, reject) {
        return request
          .put(url)
          .send(this._jsonPayload(revision, body, commitDetails))
          .set('Content-Type', 'application/vnd.api+json')
          .set('Accept', 'application/vnd.api+json')
          .set('Authorization', 'Bearer ' + token)
          .end(function(err, res) {
            if (err) { 
              reject(res); 
            } else {
              resolve();
            }
          });
      }.bind(this));
    }.bind(this));
  },

  uploadAssets: function(filesMap, context) {
    var _this = this;
    return filesMap.reduce(function(prevPromise, current) {
      return prevPromise.then(function() {
        context.log('uploading asset ' + current.file);
        return _this.uploadAsset(current.path, current.file);
      }).catch(function(e) { 
        console.log('error uploading ' + current.file + ':', e) 
      });
    }, RSVP.resolve());
  },

  uploadAsset: function(filePath, as) {
    var url = this._assetUrl();
    var token = this._token();

    return new RSVP.Promise(function(resolve, reject) {
      var req = request
        .post(url)
        .attach('asset', filePath)
        .field('file_path', as)
        .set('Authorization', 'Bearer ' + token)
        .end(function(err, res){
          if (err) {
            reject(err);
          } else {
            console.log('resolved ', as);
            resolve();
          }
        });
      return req;
    });
  },

  activate: function(revision) {
    var url   = this._buildUrl([revision, 'activate']);
    var token = this._token();
    return new Promise(function(resolve, reject) {
      return request
        .put(url)
        .set('Content-Type', 'application/vnd.api+json')
        .set('Accept', 'application/vnd.api+json')
        .set('Authorization', 'Bearer ' + token)
        .end(function(err, res){
          if (err) {<commit_msg>Remove debugging log.<commit_after>'use strict';

var CoreObject = require('core-object');
var jwt        = require('jwt-simple');
var RSVP       = require('rsvp');
var request    = require('superagent');
var fs         = require('fs');
var readFile   = RSVP.denodeify(fs.readFile);

module.exports = CoreObject.extend({
  init: function(config) {
    this.deployHost = config.deployHost;
    this.appKey     = config.appKey;
    this.userKey    = config.userKey;
    this.userSecret = config.userSecret;
  },

  uploadBuild: function(filePath, revision, commitDetails) {
    var url = this._buildUrl([revision]);
    var token = this._token();
    return this._readFileContents(filePath).then(function(body) {
      return new RSVP.Promise(function(resolve, reject) {
        return request
          .put(url)
          .send(this._jsonPayload(revision, body, commitDetails))
          .set('Content-Type', 'application/vnd.api+json')
          .set('Accept', 'application/vnd.api+json')
          .set('Authorization', 'Bearer ' + token)
          .end(function(err, res) {
            if (err) { 
              reject(res); 
            } else {
              resolve();
            }
          });
      }.bind(this));
    }.bind(this));
  },

  uploadAssets: function(filesMap, context) {
    var _this = this;
    return filesMap.reduce(function(prevPromise, current) {
      return prevPromise.then(function() {
        context.log('uploading asset ' + current.file);
        return _this.uploadAsset(current.path, current.file);
      }).catch(function(e) { 
        console.log('error uploading ' + current.file + ':', e) 
      });
    }, RSVP.resolve());
  },

  uploadAsset: function(filePath, as) {
    var url = this._assetUrl();
    var token = this._token();

    return new RSVP.Promise(function(resolve, reject) {
      var req = request
        .post(url)
        .attach('asset', filePath)
        .field('file_path', as)
        .set('Authorization', 'Bearer ' + token)
        .end(function(err, res){
          if (err) {
            reject(err);
          } else {
            resolve();
          }
        });
      return req;
    });
  },

  activate: function(revision) {
    var url   = this._buildUrl([revision, 'activate']);
    var token = this._token();
    return new Promise(function(resolve, reject) {
      return request
        .put(url)
        .set('Content-Type', 'application/vnd.api+json')
        .set('Accept', 'application/vnd.api+json')
        .set('Authorization', 'Bearer ' + token)
        .end(function(err, res){
          if (err) {
{'fraction_non_alphanumeric': 0.1496546431312356, 'fraction_numerical': 0.0, 'mean_word_length': 2.2993670886075948, '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': '6301305', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1536, 'n_words': 310}