<commit_before>const crypto = require('crypto')
const http = require('http')
const path = require('path')
const request = require('request')
const shell = require('shelljs')
const pm2 = require('pm2')
const proxy = require('http-proxy').createProxyServer({})
const config = require('./config')

config.root = config.root || ''
const port = process.env.PORT || config.port || 80
const portPart = port === 80 || port === 443 ? '' : `:${port}`
const hooksRe = new RegExp(`^(.*?//)*${config.webhook.host}/hooks`, 'i')
const GITHUB_API_HOST = 'https://api.github.com'
const headers = {
	'User-Agent': 'easy-pm',
	'Accept': 'application/vnd.github.v3+json'
}
if (config.webhook.token) {
	headers.Authorization = `token ${config.webhook.token}`
}

const routes = {}

const apps = config.apps.map(app => {
	const appPath = path.resolve(config.root, app.path || app.name)
	const port = app.port || ''
	const files = shell.ls(appPath)

	if (app.domains) {
		app.domains.forEach(domain => {
			routes[domain] = port
		})
	}

	if (files.stderr !== null) {
		if (app.repository) {
			const branch = app.branch || 'master'
			shell.exec(`git clone ${app.repository} ${appPath} && cd ${appPath} && git checkout ${branch} && npm install`)
		} else {
			console.log(`Can't find ${appPath}`)
		}
	}

	if (app.repository) {
		const [, owner, repo] = app.repository.match(/.*?github\.com.(.+?)\/(.+?)\.git/)

		if (owner && repo) {
			request({
				headers,
				url: `${GITHUB_API_HOST}/repos/${owner}/${repo}/hooks`
			}, (err, res, body) => {
				try {
					const hooks = JSON.parse(body)
					let matchedHook = ''
					const haveHooks = hooks.reduce((prev, current) => {
						if (hooksRe.test(current.config.url)) {
							matchedHook = current.id
							console.log(current.config.url)
						}
						return prev || hooksRe.test(current.config.url)
					}, false)
					if (!haveHooks) {
						request({
							headers,
							method: 'POST',
							url: `${GITHUB_API_HOST}/repos/${owner}/${repo}/hooks`,
							json: {
								name: 'web',
								active: true,
								events: ['push'],
								config: {
									url: `${config.webhook.host}${portPart}/hooks/${app.name}`,
									content_type: 'json',<commit_msg>remove extra logs<commit_after>const crypto = require('crypto')
const http = require('http')
const path = require('path')
const request = require('request')
const shell = require('shelljs')
const pm2 = require('pm2')
const proxy = require('http-proxy').createProxyServer({})
const config = require('./config')

config.root = config.root || ''
const port = process.env.PORT || config.port || 80
const portPart = port === 80 || port === 443 ? '' : `:${port}`
const hooksRe = new RegExp(`^(.*?//)*${config.webhook.host}/hooks`, 'i')
const GITHUB_API_HOST = 'https://api.github.com'
const headers = {
	'User-Agent': 'easy-pm',
	'Accept': 'application/vnd.github.v3+json'
}
if (config.webhook.token) {
	headers.Authorization = `token ${config.webhook.token}`
}

const routes = {}

const apps = config.apps.map(app => {
	const appPath = path.resolve(config.root, app.path || app.name)
	const port = app.port || ''
	const files = shell.ls(appPath)

	if (app.domains) {
		app.domains.forEach(domain => {
			routes[domain] = port
		})
	}

	if (files.stderr !== null) {
		if (app.repository) {
			const branch = app.branch || 'master'
			shell.exec(`git clone ${app.repository} ${appPath} && cd ${appPath} && git checkout ${branch} && npm install`)
		} else {
			console.log(`Can't find ${appPath}`)
		}
	}

	if (app.repository) {
		const [, owner, repo] = app.repository.match(/.*?github\.com.(.+?)\/(.+?)\.git/)

		if (owner && repo) {
			request({
				headers,
				url: `${GITHUB_API_HOST}/repos/${owner}/${repo}/hooks`
			}, (err, res, body) => {
				try {
					const hooks = JSON.parse(body)
					let matchedHook = ''
					const haveHooks = hooks.reduce((prev, current) => {
						if (hooksRe.test(current.config.url)) {
							matchedHook = current.id
						}
						return prev || hooksRe.test(current.config.url)
					}, false)
					if (!haveHooks) {
						request({
							headers,
							method: 'POST',
							url: `${GITHUB_API_HOST}/repos/${owner}/${repo}/hooks`,
							json: {
								name: 'web',
								active: true,
								events: ['push'],
								config: {
									url: `${config.webhook.host}${portPart}/hooks/${app.name}`,
									content_type: 'json',
{'fraction_non_alphanumeric': 0.19478141451132983, 'fraction_numerical': 0.004577706569008927, 'mean_word_length': 3.185823754789272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '2024939', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1470, 'n_words': 314}