<commit_before><?php

/**
 * class Project
 *
 * Represents a Drupal project that is being mirrored by HubDrop.
 *
 */
namespace HubDrop\Bundle\Service;

use Guzzle\Http\Client as GuzzleClient;
use Guzzle\Http\Exception\BadResponseException;
use Symfony\Component\HttpFoundation\Session\Session;


class Project {

  // The drupal project we want to deal with.
  public $name;

  // All of the pertinent urls for this project, including local ones.
  public $urls;

  // Whether or not the Drupal project exists
  public $exists = FALSE;

  // Whether or not the Drupal project has a mirror on GitHub
  public $mirrored = FALSE;

  // Whether or not the Drupal project is cloned locally.
  public $cloned = FALSE;

  // The default git branch this project is on.
  public $default_branch = '';

  // The current source of this project. (drupal or github)
  public $source = '';

  // GitHub committers
  public $committers = array();

  // GitHub admins
  public $admins = array();

  // GitHub Organization
  public $github_organization = '';

  /**
   * Initiate the project
   */
  public function __construct($name, HubDrop $hubdrop) {
    // Make our hubdrop service available to projects.
    $this->hubdrop = $hubdrop;

    // Set properties
    $this->name = $name = strtolower(trim($name));
    $this->urls = array(
      'drupal' => array(
        'web' =>  "http://drupal.org/project/{$this->name}",
        'ssh' => "{$hubdrop->drupal_username}@git.drupal.org:project/{$this->name}.git",
        'http' => "http://git.drupal.org/project/{$this->name}.git",
      ),
      'github' => array(
        'web' => "http://github.com/{$hubdrop->github_organization}/{$this->name}",
        'ssh' => "git@github.com:{$hubdrop->github_organization}/{$this->name}.git",
        'http' =>  "https://github.com/{$hubdrop->github_organization}/{$this->name}.git",
      ),
      'hubdrop' => array(
        'web' => "{$hubdrop->url}/project/{$this->name}",
      ),
      'localhost' => array(
        'path' => "/var/hubdrop/repos/{$this->name}.git",
      ),
    );

    // Check if the project has been cloned (and therefor, exists)
    $this->cloned = (bool) $this->checkUrl('localhost');

    // If it is cloned locally...
    if ($this->cloned){
      // We can assume the Drupal project exists.
      $this->exists = TRUE;

      // We will assume the clone is mirrored (until we can't).
      $this->mirrored = TRUE;

      // Get the default branch
      $this->default_branch = $this->getCurrentBranch();

      // Get the current source
      $this->source = $this->checkSource();

      // Get maintainers
      $config = $this->exec('git config -l');
      $config = explode("\n", $config);
      foreach ($config as $line){
        if (strpos($line, "hubdrop.committers") === 0){
          list($name, $value) = explode("=", $line);
          $names = explode('.', $name);
          $username = array_pop($names);
          $this->committers[$value] = array(
            'username' => $username,
            'uid' => $value,
          );
        }
        if (strpos($line, "hubdrop.admins") === 0){
          list($name, $value) = explode("=", $line);
          $names = explode('.', $name);
          $username = array_pop($names);
          $this->admins[$value] = array(
            'username' => $username,
            'uid' => $value,
          );
        }
      }

      // Get GitHub Organization
//      $remotes = explode("\n", $this->exec('git remote -v'));
//
//      foreach ($remotes as $line){
//        list($remote, $url, $type) = preg_split('/\s+/', $line);
////        origin	<EMAIL>:pcgroup/engageny2.git (push)
//        if ($remote == 'origin' && $type == '(push)'){
//          // @TODO: REGEX!
//          $url = str_replace('git@github.com:', 'http://github.com/', $url);
//          $url = parse_url($url);
//          $path = explode('/', $url['path']);
//          $this->github_organization = $path[0];
//          break;
//        }
//      }
      $this->github_organization = $this->hubdrop->github_organization;
    }
    // If it is not cloned locally...
    else {
      // Check to see if it exists
      $this->exists = (bool) $this->checkUrl('drupal');

      // If it does, check to see if it is mirrored yet.
      $this->mirrored = $this->exists?
        (bool) $this->checkUrl('github'):
        FALSE;

      // Set GitHub Org to match HubDrop
      $this->github_organization = $this->hubdrop->github_organization;
    }
  }

  /**
   * Gets the current "source" of the mirror.
   *
   * @return string
   *   "drupal" or "github"
   */
  public function checkSource() {
    $source = $this->exec('git config --get remote.origin.url');

    if (trim($source) == trim($this->getUrl('drupal', 'http'))){
      return 'drupal';
    }
    elseif (trim($source) == trim($this->getUrl('github', 'http'))) {
      return 'github';
    }<commit_msg>Check SSH url, not HTTTP<commit_after><?php

/**
 * class Project
 *
 * Represents a Drupal project that is being mirrored by HubDrop.
 *
 */
namespace HubDrop\Bundle\Service;

use Guzzle\Http\Client as GuzzleClient;
use Guzzle\Http\Exception\BadResponseException;
use Symfony\Component\HttpFoundation\Session\Session;


class Project {

  // The drupal project we want to deal with.
  public $name;

  // All of the pertinent urls for this project, including local ones.
  public $urls;

  // Whether or not the Drupal project exists
  public $exists = FALSE;

  // Whether or not the Drupal project has a mirror on GitHub
  public $mirrored = FALSE;

  // Whether or not the Drupal project is cloned locally.
  public $cloned = FALSE;

  // The default git branch this project is on.
  public $default_branch = '';

  // The current source of this project. (drupal or github)
  public $source = '';

  // GitHub committers
  public $committers = array();

  // GitHub admins
  public $admins = array();

  // GitHub Organization
  public $github_organization = '';

  /**
   * Initiate the project
   */
  public function __construct($name, HubDrop $hubdrop) {
    // Make our hubdrop service available to projects.
    $this->hubdrop = $hubdrop;

    // Set properties
    $this->name = $name = strtolower(trim($name));
    $this->urls = array(
      'drupal' => array(
        'web' =>  "http://drupal.org/project/{$this->name}",
        'ssh' => "{$hubdrop->drupal_username}@git.drupal.org:project/{$this->name}.git",
        'http' => "http://git.drupal.org/project/{$this->name}.git",
      ),
      'github' => array(
        'web' => "http://github.com/{$hubdrop->github_organization}/{$this->name}",
        'ssh' => "git@github.com:{$hubdrop->github_organization}/{$this->name}.git",
        'http' =>  "https://github.com/{$hubdrop->github_organization}/{$this->name}.git",
      ),
      'hubdrop' => array(
        'web' => "{$hubdrop->url}/project/{$this->name}",
      ),
      'localhost' => array(
        'path' => "/var/hubdrop/repos/{$this->name}.git",
      ),
    );

    // Check if the project has been cloned (and therefor, exists)
    $this->cloned = (bool) $this->checkUrl('localhost');

    // If it is cloned locally...
    if ($this->cloned){
      // We can assume the Drupal project exists.
      $this->exists = TRUE;

      // We will assume the clone is mirrored (until we can't).
      $this->mirrored = TRUE;

      // Get the default branch
      $this->default_branch = $this->getCurrentBranch();

      // Get the current source
      $this->source = $this->checkSource();

      // Get maintainers
      $config = $this->exec('git config -l');
      $config = explode("\n", $config);
      foreach ($config as $line){
        if (strpos($line, "hubdrop.committers") === 0){
          list($name, $value) = explode("=", $line);
          $names = explode('.', $name);
          $username = array_pop($names);
          $this->committers[$value] = array(
            'username' => $username,
            'uid' => $value,
          );
        }
        if (strpos($line, "hubdrop.admins") === 0){
          list($name, $value) = explode("=", $line);
          $names = explode('.', $name);
          $username = array_pop($names);
          $this->admins[$value] = array(
            'username' => $username,
            'uid' => $value,
          );
        }
      }

      // Get GitHub Organization
//      $remotes = explode("\n", $this->exec('git remote -v'));
//
//      foreach ($remotes as $line){
//        list($remote, $url, $type) = preg_split('/\s+/', $line);
////        origin	git@github.com:pcgroup/engageny2.git (push)
//        if ($remote == 'origin' && $type == '(push)'){
//          // @TODO: REGEX!
//          $url = str_replace('git@github.com:', 'http://github.com/', $url);
//          $url = parse_url($url);
//          $path = explode('/', $url['path']);
//          $this->github_organization = $path[0];
//          break;
//        }
//      }
      $this->github_organization = $this->hubdrop->github_organization;
    }
    // If it is not cloned locally...
    else {
      // Check to see if it exists
      $this->exists = (bool) $this->checkUrl('drupal');

      // If it does, check to see if it is mirrored yet.
      $this->mirrored = $this->exists?
        (bool) $this->checkUrl('github'):
        FALSE;

      // Set GitHub Org to match HubDrop
      $this->github_organization = $this->hubdrop->github_organization;
    }
  }

  /**
   * Gets the current "source" of the mirror.
   *
   * @return string
   *   "drupal" or "github"
   */
  public function checkSource() {
    $source = $this->exec('git config --get remote.origin.url');

    if (trim($source) == trim($this->getUrl('drupal', 'http'))){
      return 'drupal';
    }
    elseif (trim($source) == trim($this->getUrl('github', 'ssh'))) {
      return 'github';
    }
{'fraction_non_alphanumeric': 0.17778909831889964, 'fraction_numerical': 0.000815078960774325, 'mean_word_length': 2.3387755102040817, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 124, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, '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': '1772594', 'n_tokens_mistral': 3102, 'n_tokens_neox': 2990, 'n_words': 772}