<commit_before>import _ from 'lodash';
import {spawn} from './promise-array';
import {Observable, Scheduler, CompositeDisposable, SerialDisposable, Subject} from 'rx';

import './custom-rx-operators';

const d = require('debug')('surf:build-monitor');

export function getSeenRefs(refs) {
  return _.reduce(refs, (acc, x) => {
    acc.add(x.object.sha);
    return acc;
  }, new Set());
}

export default class BuildMonitor {
  constructor(cmdWithArgs, repo, maxConcurrentJobs, fetchRefs, initialRefs=null, scheduler=null, pollInterval=5000) {
    _.assign(this, {cmdWithArgs, maxConcurrentJobs, fetchRefs, scheduler, pollInterval, repo});

    this.currentBuilds = {};
    this.scheduler = this.scheduler || Scheduler.default;
    this.currentRunningMonitor = new SerialDisposable();
    this.buildsToActuallyExecute = new Subject();

    if (initialRefs) {
      this.seenCommits = getSeenRefs(initialRefs);
    } else {
      this.seenCommits = new Set();
    }
  }

  dispose() {
    this.currentRunningMonitor.dispose();
  }

  runBuild(ref) {
    let args = _.clone(this.cmdWithArgs).splice(1).concat([ref.object.sha]);
    let envToAdd = {
      'SURF_SHA1': ref.object.sha,
      'SURF_REPO': this.repo,
      'SURF_REF': ref.ref.replace(/^refs\/heads\//, '')
    };
    
    if (ref.object.pr) {<commit_msg>Add nwo too<commit_after>import _ from 'lodash';
import {spawn} from './promise-array';
import {Observable, Scheduler, CompositeDisposable, SerialDisposable, Subject} from 'rx';
import {getNwoFromRepoUrl} from './github-api';

import './custom-rx-operators';

const d = require('debug')('surf:build-monitor');

export function getSeenRefs(refs) {
  return _.reduce(refs, (acc, x) => {
    acc.add(x.object.sha);
    return acc;
  }, new Set());
}

export default class BuildMonitor {
  constructor(cmdWithArgs, repo, maxConcurrentJobs, fetchRefs, initialRefs=null, scheduler=null, pollInterval=5000) {
    _.assign(this, {cmdWithArgs, maxConcurrentJobs, fetchRefs, scheduler, pollInterval, repo});

    this.currentBuilds = {};
    this.scheduler = this.scheduler || Scheduler.default;
    this.currentRunningMonitor = new SerialDisposable();
    this.buildsToActuallyExecute = new Subject();

    if (initialRefs) {
      this.seenCommits = getSeenRefs(initialRefs);
    } else {
      this.seenCommits = new Set();
    }
  }

  dispose() {
    this.currentRunningMonitor.dispose();
  }

  runBuild(ref) {
    let args = _.clone(this.cmdWithArgs).splice(1).concat([ref.object.sha]);
    let envToAdd = {
      'SURF_SHA1': ref.object.sha,
      'SURF_REPO': this.repo,
      'SURF_NWO': getNwoFromRepoUrl(this.repo),
      'SURF_REF': ref.ref.replace(/^refs\/heads\//, '')
    };
    
    if (ref.object.pr) {
{'fraction_non_alphanumeric': 0.15003668378576668, 'fraction_numerical': 0.004402054292002935, 'mean_word_length': 3.8265486725663718, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1264833', 'n_tokens_mistral': 953, 'n_tokens_neox': 924, 'n_words': 176}