<commit_before>'use strict';

/*
 * Backchannel server allows workers to stream messages back to the Node server
 * in a line-buffered way. Uses SSL.
 */

var _ = require('lodash');
var async = require('async');
var jobs = require('./jobs');
var common = require('./common');
var utils = require('./utils');
var config = require('./config');
var models = require('./models');

var Job = models.Job;
var User = models.User;
var Project = models.Project;

function striderJson(provider, project, ref, done) {
  function finished(err, contents) {
    if (err || !contents) return done(err);

    var data = {};

    try {
      data = JSON.parse(contents);
    } catch (e) {
      console.warn('Strider config is invalid JSON for', project, ref);
      console.log(contents);
    }

    done(undefined, data);
  }

  if (!provider.hosted) {
    return provider.getFile('strider.json', ref, project.provider.config, project, finished);
  }

  var account = project.creator.account(project.provider.id, project.provider.account);

  provider.getFile('strider.json', ref, account, project.provider.config, project, finished);
}

// Prepare the job for execution, save to database, and fire off a `job.new` event.
//
// job is expected to be populated with:
// - a trigger
// - a ref
// - the project name
// - the user id (if applicable)
// - type
// - created timestamp
// XXX: should this function go in a different file? idk. We'll
//      definitely move it around when we make strider OO.
function prepareJob(emitter, job) {
  Project.findOne({name: job.project}).populate('creator').exec(function (err, project) {
    if (err || !project) return console.error('job.prepare - failed to get project', job.project, err)
    // ok so the project is real, we can go ahead and save this job
    var provider = common.extensions.provider[project.provider.id];<commit_msg>Fix fetching strider.json over a Github repository.<commit_after>'use strict';

/*
 * Backchannel server allows workers to stream messages back to the Node server
 * in a line-buffered way. Uses SSL.
 */

var _ = require('lodash');
var async = require('async');
var jobs = require('./jobs');
var common = require('./common');
var utils = require('./utils');
var config = require('./config');
var models = require('./models');

var Job = models.Job;
var User = models.User;
var Project = models.Project;

function striderJson(provider, project, ref, done) {
  function finished(err, contents) {
    if (err || !contents) return done(err);

    var data = {};

    try {
      data = JSON.parse(contents);
    } catch (e) {
      console.warn('Strider config is invalid JSON for', project, ref);
      console.log(contents);
    }

    done(undefined, data);
  }

  if (!provider.hosted) {
    return provider.getFile('strider.json', ref, project.provider.config, project, finished);
  }

  var account = project.creator.account(project.provider.id, project.provider.account);

  provider.getFile('strider.json', ref, account.config, project.provider.config, project, finished);
}

// Prepare the job for execution, save to database, and fire off a `job.new` event.
//
// job is expected to be populated with:
// - a trigger
// - a ref
// - the project name
// - the user id (if applicable)
// - type
// - created timestamp
// XXX: should this function go in a different file? idk. We'll
//      definitely move it around when we make strider OO.
function prepareJob(emitter, job) {
  Project.findOne({name: job.project}).populate('creator').exec(function (err, project) {
    if (err || !project) return console.error('job.prepare - failed to get project', job.project, err)
    // ok so the project is real, we can go ahead and save this job
    var provider = common.extensions.provider[project.provider.id];
{'fraction_non_alphanumeric': 0.1391465677179963, 'fraction_numerical': 0.0, 'mean_word_length': 3.503579952267303, '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': '4581387', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1081, 'n_words': 383}