<commit_before>var promisify = require('promisify-node');
var childProcess = require('child_process');
var readlineSync = require('readline-sync');

var Travis = require('travis-ci');
var travis = new Travis({ version: '2.0.0' });

travis.authenticate = promisify(travis.authenticate);
travis.users.get = promisify(travis.users.get);
travis.users.sync.post = promisify(travis.users.sync.post);

var GitHub = require('github');
var github = new GitHub({
  version: '3.0.0',
  protocol: 'https',
  headers: {
    'user-agent': 'Oghliner',
  },
});

var liveUtils = {
  repoName: 'test_oghliner_live_' + process.version + '_' + process.pid,
  githubNote: 'test' + process.version + '_' + process.pid,
  githubNoteURL: 'http://www.test.org/' + process.version + '_' + process.pid,
  githubToken: null,
  getTokenId: getTokenId,
  createAuthorization: createAuthorization,
  deleteAuthorization: deleteAuthorization,
  createRepo: createRepo,
  deleteRepo: deleteRepo,
  getBranch: getBranch,
  cleanup: cleanup,
  spawn: spawn,
};

var githubTokenId;
var useOTP = false;

function createRepo(autoInit) {
  return new Promise(function(resolve, reject) {
    github.repos.create({
      name: liveUtils.repoName,
      auto_init: autoInit,
    }, function(err) {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
}

function deleteRepo(username) {
  return new Promise(function(resolve, reject) {
    github.repos.delete({
      user: username,
      repo: liveUtils.repoName,
    }, function(err) {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
}

function getBranch(username) {
  return new Promise(function(resolve, reject) {
    setTimeout(function() {
      github.repos.getBranch({
        user: username,
        repo: liveUtils.repoName,
        branch: 'gh-pages',
      }, function(err, res) {
        if (err) {
          reject(err);
        } else {
          resolve(res);
        }
      });
    }, 3000);
  });
}

function getTokenId(username, password, note, noteURL, page) {
  github.authenticate({
    type: 'basic',
    username: username,
    password: password,
  });

  page = page || 1;

  return new Promise(function(resolve, reject) {
    github.authorization.getAll({
      page: page,
      headers: useOTP ? { 'X-GitHub-OTP': readlineSync.question('Auth Code: ') } : {},
    }, function(err, res) {
      if (err) {
        reject(err);
        return;
      }

      if (res.length === 0) {
        reject(new Error('Token not found'));
      }

      for (var i = 0; i < res.length; i++) {
        if (res[i].note === note && res[i].note_url === noteURL) {
          resolve(res[i].id);
          return;
        }<commit_msg>Add missing return statement<commit_after>var promisify = require('promisify-node');
var childProcess = require('child_process');
var readlineSync = require('readline-sync');

var Travis = require('travis-ci');
var travis = new Travis({ version: '2.0.0' });

travis.authenticate = promisify(travis.authenticate);
travis.users.get = promisify(travis.users.get);
travis.users.sync.post = promisify(travis.users.sync.post);

var GitHub = require('github');
var github = new GitHub({
  version: '3.0.0',
  protocol: 'https',
  headers: {
    'user-agent': 'Oghliner',
  },
});

var liveUtils = {
  repoName: 'test_oghliner_live_' + process.version + '_' + process.pid,
  githubNote: 'test' + process.version + '_' + process.pid,
  githubNoteURL: 'http://www.test.org/' + process.version + '_' + process.pid,
  githubToken: null,
  getTokenId: getTokenId,
  createAuthorization: createAuthorization,
  deleteAuthorization: deleteAuthorization,
  createRepo: createRepo,
  deleteRepo: deleteRepo,
  getBranch: getBranch,
  cleanup: cleanup,
  spawn: spawn,
};

var githubTokenId;
var useOTP = false;

function createRepo(autoInit) {
  return new Promise(function(resolve, reject) {
    github.repos.create({
      name: liveUtils.repoName,
      auto_init: autoInit,
    }, function(err) {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
}

function deleteRepo(username) {
  return new Promise(function(resolve, reject) {
    github.repos.delete({
      user: username,
      repo: liveUtils.repoName,
    }, function(err) {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
}

function getBranch(username) {
  return new Promise(function(resolve, reject) {
    setTimeout(function() {
      github.repos.getBranch({
        user: username,
        repo: liveUtils.repoName,
        branch: 'gh-pages',
      }, function(err, res) {
        if (err) {
          reject(err);
        } else {
          resolve(res);
        }
      });
    }, 3000);
  });
}

function getTokenId(username, password, note, noteURL, page) {
  github.authenticate({
    type: 'basic',
    username: username,
    password: password,
  });

  page = page || 1;

  return new Promise(function(resolve, reject) {
    github.authorization.getAll({
      page: page,
      headers: useOTP ? { 'X-GitHub-OTP': readlineSync.question('Auth Code: ') } : {},
    }, function(err, res) {
      if (err) {
        reject(err);
        return;
      }

      if (res.length === 0) {
        reject(new Error('Token not found'));
        return;
      }

      for (var i = 0; i < res.length; i++) {
        if (res[i].note === note && res[i].note_url === noteURL) {
          resolve(res[i].id);
          return;
        }
{'fraction_non_alphanumeric': 0.15171288743882544, 'fraction_numerical': 0.004712706180895414, 'mean_word_length': 2.75118966689327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6228474', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1808, 'n_words': 376}