<commit_before>"use strict";
require('es6-shim');
require('prfun');

var program = require('commander');
var json = require('../package.json');

var fs = require('fs');
var Pusher = require('pusher-client');
var url = require('url');

var p = require('./p');
var request = require('./retry-request');

var CHILD_IGNORE = { childOptions: { stdio: 'ignore' } };
var readFile = Promise.promisify(fs.readFile, false, fs);

program
	.version(json.version)
	.usage('[options] [github project]')
	.option(
		'--travis-api <url>',
		'Travis API endpoint [https://api.travis-ci.org]',
		'https://api.travis-ci.org'
	).option(
		'-j, --job <n>',
		'Only follow the specified job (job numbers start at 1)'
	);

program.parse(process.argv);

if (program.args.length > 1) {
	console.error('Too many arguments.');
	return 1;
}

var getUserAgent = function(repo) {
	return json.name + '/' + json.version + ' (' +
		'node ' + process.version + ' ' + process.platform + ' ' + process.arch +
		') ' + repo;
};

var getRepoName = function() {
	return Promise.resolve(program.args[0]).then(function(reponame) {
		if (reponame) { return reponame; }
		// look in ./package.json
		return readFile(
			'./package.json', { encoding: 'utf8' }
		).then(function(data) {
			var json = JSON.parse(data);
			if (json.repository && json.repository.type === 'git') {
				var m =
					/^(https?:\/\/github.com\/)?([^\/]+)\/([^\/]+?)(\.git)?$/.
					exec(json.repository.url || '');
				if (m) {
					return m[2] + '/' + m[3];
				}
			}
		});
	}).catch(function(e) { /* ignore */ }).then(function(reponame) {
		if (reponame) { return reponame; }
		// XXX look in .git/config?
		throw new Error("Can't determine github repo name.");
	});
};

// ensure that there is a github remote, named 'github'
var ensureRemote = function(repo) {
	return p.spawn('git', ['remote', 'show', 'github'], CHILD_IGNORE).then(function() {
		/* ok, github already exists */
	}, function(e) {
		/* doesn't exist, create it! */
		return p.spawn('git', ['remote','add','github','<EMAIL>:'+repo]);
	});
};<commit_msg>Get repo name from 'origin' or 'github' git remotes.<commit_after>"use strict";
require('es6-shim');
require('prfun');

var program = require('commander');
var json = require('../package.json');

var fs = require('fs');
var Pusher = require('pusher-client');
var url = require('url');

var p = require('./p');
var request = require('./retry-request');

var CHILD_IGNORE = { childOptions: { stdio: 'ignore' } };
var readFile = Promise.promisify(fs.readFile, false, fs);

program
	.version(json.version)
	.usage('[options] [github project]')
	.option(
		'--travis-api <url>',
		'Travis API endpoint [https://api.travis-ci.org]',
		'https://api.travis-ci.org'
	).option(
		'-j, --job <n>',
		'Only follow the specified job (job numbers start at 1)'
	);

program.parse(process.argv);

if (program.args.length > 1) {
	console.error('Too many arguments.');
	return 1;
}

var getUserAgent = function(repo) {
	return json.name + '/' + json.version + ' (' +
		'node ' + process.version + ' ' + process.platform + ' ' + process.arch +
		') ' + repo;
};

var gitRemoteRegex =
	/Push\s+URL:\s+(?:https?:\/\/github.com\/|git@github.com:)([^\/]+)\/([^\/]+?)(?:\.git)?\s/;

var getRepoName = function() {
	return Promise.resolve(program.args[0]).then(function(reponame) {
		if (reponame) { return reponame; }
		// look in .git/config for 'github' remote
		return p.execFile('git', ['remote','show','github']).then(function(out){
			var m = gitRemoteRegex.exec(out.stdout);
			if (m) {
				return m[1] + '/' + m[2];
			}
		});
	}).catch(function(e) { /* ignore */ }).then(function(reponame) {
		if (reponame) { return reponame; }
		// look in .git/config for 'origin' remote
		return p.execFile('git', ['remote','show','origin']).then(function(out){
			var m = gitRemoteRegex.exec(out.stdout);
			if (m) {
				return m[1] + '/' + m[2];
			}
		});
	}).catch(function(e) { /* ignore */ }).then(function(reponame) {
		if (reponame) { return reponame; }
		// look in ./package.json
		return readFile(
			'./package.json', { encoding: 'utf8' }
		).then(function(data) {
			var json = JSON.parse(data);
			if (json.repository && json.repository.type === 'git') {
				var m =
					/^(https?:\/\/github.com\/)?([^\/]+)\/([^\/]+?)(\.git)?$/.
					exec(json.repository.url || '');
				if (m) {
					return m[2] + '/' + m[3];
				}
			}
		});
	}).catch(function(e) { /* ignore */ }).then(function(reponame) {
		if (reponame) { return reponame; }
		throw new Error("Can't determine github repo name.");
	});
};

// ensure that there is a github remote, named 'github'
var ensureRemote = function(repo) {
	return p.spawn('git', ['remote', 'show', 'github'], CHILD_IGNORE).then(function() {
		/* ok, github already exists */
	}, function(e) {
		/* doesn't exist, create it! */
		return p.spawn('git', ['remote','add','github','<EMAIL>:'+repo]);
	});
};
{'fraction_non_alphanumeric': 0.22602459016393442, 'fraction_numerical': 0.004098360655737705, 'mean_word_length': 3.5702247191011236, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '2166142', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1765, 'n_words': 383}