<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const exec = require('child_process').exec;
const fs = require('fs');
const path = require('path');
const util = require('util');

const version = require('../../package.json').version;

// See if config/version.json exists (part of rpm builds)
var commitHash = (function() {
  var sha;
  try {
    sha = require('../../config/version.json');
    sha = sha.version.hash;
  } catch(e) { /* ignore */ }
  return sha;
})();

module.exports = {
  handler: function index(req, reply) {
    function sendReply() {
      reply({
        version: version,
        commit: commitHash,
      }).spaces(2);
    }

    if (commitHash) {
      return sendReply();
    }

     // figure it out from git (either '.git', or '/home/app/git' for AwsBox)
    var gitDir;
    if (!fs.existsSync(path.join(__dirname, '..', '..', '.git'))) {
      // try at '/home/app/git' for AwsBox deploys
      gitDir = path.sep + path.join('home', 'app', 'git');
    }
    var cmd = util.format('git %s rev-parse HEAD',
        gitDir ? '--git-dir=' + gitDir : '');
    exec(cmd, function(err, stdout) {
      commitHash = stdout.replace(/\s+/, '');
      return sendReply();
    });
  }
};<commit_msg>make it work on fxa-dev boxes too<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const exec = require('child_process').exec;
const fs = require('fs');
const path = require('path');
const util = require('util');

const version = require('../../package.json').version;

// See if config/version.json exists (part of rpm builds)
var commitHash = (function() {
  var sha;
  try {
    sha = require('../../config/version.json');
    sha = sha.version.hash;
  } catch(e) { /* ignore */ }
  return sha;
})();

module.exports = {
  handler: function index(req, reply) {
    function sendReply() {
      reply({
        version: version,
        commit: commitHash,
      }).spaces(2);
    }

    if (commitHash) {
      return sendReply();
    }

    // figure it out from git (either '.git', or '/home/app/git' for AwsBox)
    var gitDir = path.resolve(__dirname, '..', '..', '.git');
    if (!fs.existsSync(gitDir)) {
      // try at '/home/app/git' for AwsBox deploys
      gitDir = path.sep + path.join('home', 'app', 'git');
    }
    var cmd = util.format('git --git-dir=%s rev-parse HEAD', gitDir);
    exec(cmd, function(err, stdout) {
      commitHash = stdout.replace(/\s+/, '');
      return sendReply();
    });
  }
};
{'fraction_non_alphanumeric': 0.17636494252873564, 'fraction_numerical': 0.0035919540229885057, 'mean_word_length': 2.6405228758169934, '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': '1502844', 'n_tokens_mistral': 910, 'n_tokens_neox': 887, 'n_words': 269}