<commit_before>const express = require('express');
const bodyParser = require('body-parser');
// const cookieParser = require('cookie-parser');
const ChannelConfig = require('./Models/ChannelConfig');
const GitlabEventHandler = require('./Gitlab/EventHandler');
const bot = require('./Discord');
const addons = require('yappybots-addons');

const app = express();
const port = process.env.YAPPY_GITLAB_PORT || process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 8080;
const ip = process.env.YAPPY_GITLAB_IP || process.env.OPENSHIFT_NODEJS_IP || process.env.IP || null;

app.set('view engine', 'hbs');

app.use(bodyParser.json({
  limit: '250kb',
}));

// app.use(cookieParser());

app.get('/', (req, res) => {
  const repos = new Set(ChannelConfig._data.reduce((a, b) => a.concat(b.repos), []));
  const status = bot.statuses[bot.status];
  const statusColor = bot.statusColors[bot.status];
  res.render('index', {
    bot, repos, status, statusColor,
    layout: 'layout',
  });
});

app.post('/', (req, res) => {
  const event = req.headers['x-gitlab-event'];
  const eventName = event && event.replace(` Hook`, '').replace(/ /g, '_').toLowerCase();
  const data = req.body;

  if (!event || !data || !data.project) return res.status(403).send('Invalid data. Plz use Gitlab webhooks.');

  const repoMatch = /(\S+?)(?:\/\S+)?\/(\S+)/.exec(data.project.path_with_namespace);
  const repo = `${repoMatch[1]}/${repoMatch[2]}`;
  const channels = ChannelConfig.FindByRepo(repo);
  const actionText = data.object_attributes && data.object_attributes.action ? `/${data.object_attributes.action}` : '';
  Log.verbose(`GitLab | ${repo} - ${eventName}${actionText} (${channels.size} channels)`);
  res.send(`${data.project.path_with_namespace} : Received ${eventName}${actionText}, emitting to ${channels.size} channels...`);
  const eventResponse = GitlabEventHandler.use(data, event);

  const handleError = (resp, channel) => {
    const err = resp && resp.body;
    const errors = ['Forbidden', 'Missing Access'];
    if (!res || !err) return;
    if (errors.includes(err.message) || (err.error && errors.includes(err.error.message))) {<commit_msg>fix(web): fix url encoded not working<commit_after>const express = require('express');
const bodyParser = require('body-parser');
// const cookieParser = require('cookie-parser');
const ChannelConfig = require('./Models/ChannelConfig');
const GitlabEventHandler = require('./Gitlab/EventHandler');
const bot = require('./Discord');
const addons = require('yappybots-addons');

const app = express();
const port = process.env.YAPPY_GITLAB_PORT || process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 8080;
const ip = process.env.YAPPY_GITLAB_IP || process.env.OPENSHIFT_NODEJS_IP || process.env.IP || null;

app.set('view engine', 'hbs');

app.use(bodyParser.urlencoded({
  extended: true,
  limit: '250kb',
}));

app.use(bodyParser.json({
  limit: '250kb',
}));

app.use((req, res, next) => {
  if (req.headers['content-type'] === 'application/x-www-form-urlencoded' && req.body && req.body.payload) {
    req.body = JSON.parse(req.body.payload);
  }
  next();
});

app.get('/', (req, res) => {
  const repos = new Set(ChannelConfig._data.reduce((a, b) => a.concat(b.repos), []));
  const status = bot.statuses[bot.status];
  const statusColor = bot.statusColors[bot.status];
  res.render('index', {
    bot, repos, status, statusColor,
    layout: 'layout',
  });
});

app.post('/', (req, res) => {
  const event = req.headers['x-gitlab-event'];
  const eventName = event && event.replace(` Hook`, '').replace(/ /g, '_').toLowerCase();
  const data = req.body;

  if (!event || !data || !data.project) return res.status(403).send('Invalid data. Plz use Gitlab webhooks.');

  const repoMatch = /(\S+?)(?:\/\S+)?\/(\S+)/.exec(data.project.path_with_namespace);
  const repo = `${repoMatch[1]}/${repoMatch[2]}`;
  const channels = ChannelConfig.FindByRepo(repo);
  const actionText = data.object_attributes && data.object_attributes.action ? `/${data.object_attributes.action}` : '';
  Log.verbose(`GitLab | ${repo} - ${eventName}${actionText} (${channels.size} channels)`);
  res.send(`${data.project.path_with_namespace} : Received ${eventName}${actionText}, emitting to ${channels.size} channels...`);
  const eventResponse = GitlabEventHandler.use(data, event);

  const handleError = (resp, channel) => {
    const err = resp && resp.body;
    const errors = ['Forbidden', 'Missing Access'];
    if (!res || !err) return;
    if (errors.includes(err.message) || (err.error && errors.includes(err.error.message))) {
{'fraction_non_alphanumeric': 0.19750656167979003, 'fraction_numerical': 0.005905511811023622, 'mean_word_length': 4.773989898989899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '555513', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1497, 'n_words': 308}