<commit_before>var http  = require('http');
var https = require('https');
var _     = require('underscore');
var async = require('async');
var githubAPI = require('github');

/*
  This function will parse a github path into its parts.

*/
var parseGitPath = function(input) {

  var parts  = input.split(':');
  var domain = parts[0].split('@');
  var git    = parts[1].split('/');

  var gitData = {
     url: input,
     location: {
       domain: domain[1],
       user: domain[0]
     },
     repo: {
        user: git[0],
        file: git[1],
        name: git[1].split('.')[0],
        path: parts[1]
     }
  };

  return gitData;
}

/*
  This function provides an express endpoint for the Github Repo
  build process. This collects the repo path, desired build and 
  misc values and will trigger the WebHook Post Receive code.

*/
exports.info = function(req, res) {

  var server = require('../config.json');

  var data = {
    name:         req.params.branch,
    path:         req.urlparams.path,
    branch:       req.urlparams.branch,
    repositories: server.repositories,
    branches:     []
  }

  if (req.urlparams.path) {

    // Run the gitpath through to get its parts.
    var gitData = parseGitPath( req.urlparams.path );

    // Setup the github API. 
    // TODO: Move this to a better place. Maybe in the App.js file.

    var github = new githubAPI({ version: '3.0.0' });
    github.authenticate({ type: 'oauth', token: req.session.user.access_token });

    // Setup the opts for a github Query. 
    // TODO: Need to build in some caching to keep the rate-limit
    // from causing issues.

    var opt = {
      repo:   gitData.repo.name,
      user:   gitData.repo.user
    };

    github.repos.getBranches(opt, function(err, branchData) {
      if (err) console.log(err);

      // Dump the Branches in to the data.
      data.branches = branchData;

      res.render('heroku_info', { data: data }, function(err, html) {
        if (err) return res.render('error', { title: '', message: err.message });
        res.end(html);
      });
    });

  } else {
    res.render('heroku_info', { data: data }, function(err, html) {
      if (err) return res.render('error', { title: '', message: err.message });
      res.end(html);
    });
  }

}

/*

  This function spoofs the github post receive webhook and will
  call the /build2 (PUBLIC) endpoint with a payload. This will
  trigger the Git Clone/Fetch and the resulting Heroku lookup
  and deploy process.

*/
exports.deploy = function(req, res) {

  var repoPath   = req.body.repoPath;
  var repoBranch = req.params.repoBranch;

  // Run the gitpath through to get its parts.
  var gitData = parseGitPath( req.body.repoPath );

  // Build the mock to send to the WebHook URL.
  var data = {
    repository: {
      name: gitData.repo.name,
      url: repoPath
    }, 
    ref: 'refs/heads/' + req.body.repoBranch 
  };

  var jsonData = JSON.stringify( { payload: JSON.stringify(data) } );<commit_msg>Fixed a send request for html<commit_after>var http  = require('http');
var https = require('https');
var _     = require('underscore');
var async = require('async');
var githubAPI = require('github');

/*
  This function will parse a github path into its parts.

*/
var parseGitPath = function(input) {

  var parts  = input.split(':');
  var domain = parts[0].split('@');
  var git    = parts[1].split('/');

  var gitData = {
     url: input,
     location: {
       domain: domain[1],
       user: domain[0]
     },
     repo: {
        user: git[0],
        file: git[1],
        name: git[1].split('.')[0],
        path: parts[1]
     }
  };

  return gitData;
}

/*
  This function provides an express endpoint for the Github Repo
  build process. This collects the repo path, desired build and 
  misc values and will trigger the WebHook Post Receive code.

*/
exports.info = function(req, res) {

  var server = require('../config.json');

  var data = {
    name:         req.params.branch,
    path:         req.urlparams.path,
    branch:       req.urlparams.branch,
    repositories: server.repositories,
    branches:     []
  }

  if (req.urlparams.path) {

    // Run the gitpath through to get its parts.
    var gitData = parseGitPath( req.urlparams.path );

    // Setup the github API. 
    // TODO: Move this to a better place. Maybe in the App.js file.

    var github = new githubAPI({ version: '3.0.0' });
    github.authenticate({ type: 'oauth', token: req.session.user.access_token });

    // Setup the opts for a github Query. 
    // TODO: Need to build in some caching to keep the rate-limit
    // from causing issues.

    var opt = {
      repo:   gitData.repo.name,
      user:   gitData.repo.user
    };

    github.repos.getBranches(opt, function(err, branchData) {
      if (err) console.log(err);

      // Dump the Branches in to the data.
      data.branches = branchData;

      res.render('heroku_info', { data: data }, function(err, html) {
        if (err) return res.render('error', { title: '', message: err.message });
        res.send(html);
      });
    });

  } else {
    res.render('heroku_info', { data: data }, function(err, html) {
      if (err) return res.render('error', { title: '', message: err.message });
      res.send(html);
    });
  }

}

/*

  This function spoofs the github post receive webhook and will
  call the /build2 (PUBLIC) endpoint with a payload. This will
  trigger the Git Clone/Fetch and the resulting Heroku lookup
  and deploy process.

*/
exports.deploy = function(req, res) {

  var repoPath   = req.body.repoPath;
  var repoBranch = req.params.repoBranch;

  // Run the gitpath through to get its parts.
  var gitData = parseGitPath( req.body.repoPath );

  // Build the mock to send to the WebHook URL.
  var data = {
    repository: {
      name: gitData.repo.name,
      url: repoPath
    }, 
    ref: 'refs/heads/' + req.body.repoBranch 
  };

  var jsonData = JSON.stringify( { payload: JSON.stringify(data) } );
{'fraction_non_alphanumeric': 0.13251001335113485, 'fraction_numerical': 0.0043391188251001335, 'mean_word_length': 2.508782201405152, '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': '1019633', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1859, 'n_words': 585}