<commit_before>/*!
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

var path = require('path');
var uniq = require('array-uniq');
var globby = require('globby');
var execSync = require('child_process').execSync;
var extend = require('extend');

require('shelljs/global');

/**
 * google-cloud-node root directory.. useful in case we need to cd
 */
var ROOT_DIR = path.join(__dirname, '..');

module.exports.ROOT_DIR = ROOT_DIR;

/**
 * Helper class to make install dependencies + running tests easier to read
 * and less error prone.
 *
 * @class Module
 * @param {string} name - The module name (e.g. common, bigquery, etc.)
 */
function Module(name) {
  if (!(this instanceof Module)) {
    return new Module(name);
  }

  this.name = name;
  this.directory = path.join(ROOT_DIR, 'packages', name);

  var pkgJson = require(path.join(this.directory, 'package.json'));

  this.packageName = pkgJson.name;
  this.dependencies = Object.keys(pkgJson.devDependencies || {});
}

/**
 * Umbrella module name.
 *
 * @static
 */
Module.UMBRELLA = 'google-cloud';

/**
 * Retrieves a list of modules that are ahead of origin/master. We do this by
 * creating a temporary remote branch that points official master branch.
 * We then do a git diff against the two to get a list of files. From there we
 * only care about either JS or JSON files being changed.
 *
 * @static
 * @return {Module[]} modules - The updated modules.
 */
Module.getUpdated = function() {
  cd(ROOT_DIR);

  var output = run('git diff HEAD^ --name-only', {
    stdio: null // prevents piping to the console
  });

  var files = output.trim().split('\n');
  var modules = files.filter(function(file) {
    return /^packages\/.+\.js/.test(file);
  }).map(function(file) {
    return file.split('/')[1];
  });

  return uniq(modules).map(Module);
};

/**
 * Builds docs for all modules
 *
 * @static
 */<commit_msg>testing: change diff command based on pr/merge (#1620)<commit_after>/*!
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

var path = require('path');
var uniq = require('array-uniq');
var globby = require('globby');
var execSync = require('child_process').execSync;
var extend = require('extend');

require('shelljs/global');

/**
 * google-cloud-node root directory.. useful in case we need to cd
 */
var ROOT_DIR = path.join(__dirname, '..');

module.exports.ROOT_DIR = ROOT_DIR;

/**
 * Helper class to make install dependencies + running tests easier to read
 * and less error prone.
 *
 * @class Module
 * @param {string} name - The module name (e.g. common, bigquery, etc.)
 */
function Module(name) {
  if (!(this instanceof Module)) {
    return new Module(name);
  }

  this.name = name;
  this.directory = path.join(ROOT_DIR, 'packages', name);

  var pkgJson = require(path.join(this.directory, 'package.json'));

  this.packageName = pkgJson.name;
  this.dependencies = Object.keys(pkgJson.devDependencies || {});
}

/**
 * Umbrella module name.
 *
 * @static
 */
Module.UMBRELLA = 'google-cloud';

/**
 * Retrieves a list of modules that are ahead of origin/master. We do this by
 * creating a temporary remote branch that points official master branch.
 * We then do a git diff against the two to get a list of files. From there we
 * only care about either JS or JSON files being changed.
 *
 * @static
 * @return {Module[]} modules - The updated modules.
 */
Module.getUpdated = function() {
  var command = ['git diff'];

  cd(ROOT_DIR);

  if (!isPushToMaster()) {
    run([
      'git remote add temp',
      'https://github.com/GoogleCloudPlatform/google-cloud-node.git'
    ]);

    run('git fetch -q temp');
    command.push('HEAD', 'temp/master');
  } else {
    command.push('HEAD^');
  }

  command.push('--name-only');

  var output = run(command, { stdio: null });
  var files = output.trim().split('\n');
  var modules = files.filter(function(file) {
    return /^packages\/.+\.js/.test(file);
  }).map(function(file) {
    return file.split('/')[1];
  });

  return uniq(modules).map(Module);
};

/**
 * Builds docs for all modules
 *
 * @static
 */
{'fraction_non_alphanumeric': 0.1351610429447853, 'fraction_numerical': 0.004217791411042945, 'mean_word_length': 3.5404699738903394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, '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': '4366417', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1529, 'n_words': 558}