<commit_before>#!/usr/bin/env php

<?php

class GitBchq_Mini {

    protected $_apiKey;
    protected $_baseUrl;
    protected $_projectId;

    public function __construct($apiKey, $baseUrl, $projectId) {
        $this->_apiKey = $apiKey;
        $this->_baseUrl = $baseUrl;
        $this->_projectId = $projectId;
    }

    public function buildRoute(Array $urlArgs) {
        $request = '';
        foreach($urlArgs as $arg => $value) {
            $request .= "/$arg/$value";
        }

        return $request;
    }

    private function curl($route = '') {
        $curl = curl_init($this->_baseUrl . $route);
        curl_setopt_array($curl, array(
            CURLOPT_HTTPHEADER => array(
                'Accept: application/xml',
                'Content-type: application/xml'
            ),
            
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_USERPWD => $this->_apiKey . ":"
        ));

        return curl_exec($curl);
    }

    public function getMessages() {
        $route = $this->buildRoute(array(
            'projects' => $this->_projectId,
            'posts' => ''
        ));

        $messagesXml = new SimpleXMLElement($this->curl($route));
        $messagesList = array();
        foreach($messagesXml as $message) {
            $messagesList["$message->id"] = "$message->title";
        }

        return $messagesList;
    }
}

$BCHQ_APIKEY=trim(`git config --get basecamp.apikey`);
$BCHQ_BASE_URL=trim(`git config --get basecamp.baseurl`);
$BCHQ_PROJECT_ID=trim(`git config --get basecamp.projectid`);
$GitBchq = new GitBchq_Mini($BCHQ_APIKEY, $BCHQ_BASE_URL, $BCHQ_PROJECT_ID);<commit_msg>Added some basic git commands<commit_after>#!/usr/bin/env php

<?php

class GitBchq_Mini {

    protected $_apiKey;
    protected $_baseUrl;
    protected $_projectId;

    public function __construct($apiKey, $baseUrl, $projectId) {
        $this->_apiKey = $apiKey;
        $this->_baseUrl = $baseUrl;
        $this->_projectId = $projectId;
    }

    public function buildRoute(Array $urlArgs) {
        $request = '';
        foreach($urlArgs as $arg => $value) {
            $request .= "/$arg/$value";
        }

        return $request;
    }

    private function curl($route = '') {
        $curl = curl_init($this->_baseUrl . $route);
        curl_setopt_array($curl, array(
            CURLOPT_HTTPHEADER => array(
                'Accept: application/xml',
                'Content-type: application/xml'
            ),
            
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_USERPWD => $this->_apiKey . ":"
        ));

        return curl_exec($curl);
    }

    public function getMessages() {
        $route = $this->buildRoute(array(
            'projects' => $this->_projectId,
            'posts' => ''
        ));

        $messagesXml = new SimpleXMLElement($this->curl($route));
        $messagesList = array();
        foreach($messagesXml as $message) {
            $messagesList["$message->id"] = "$message->title";
        }

        return $messagesList;
    }

    public function getLastCommit() {
        $logMessage = trim(`git log -1 --date=rfc -M -C --stat --pretty=medium --color`);
        $ansiTextile = array(
            chr(27) . "[33m" => '%{color:orange}',
            chr(27) . "[m" => '%',
            chr(27) . "[32m" => '%{color:green}',
            chr(27) . "[31m" => '%{color:red}'
        );

        $logMessage = str_replace(array_keys($ansiTextile), $ansiTextile, $logMessage);
            
        return $logMessage;
    }


    public function getPatch() {
        $diff = trim(`git diff -p -1`);

        return $diff;
    }
}

$BCHQ_APIKEY=trim(`git config --get basecamp.apikey`);
$BCHQ_BASE_URL=trim(`git config --get basecamp.baseurl`);
$BCHQ_PROJECT_ID=trim(`git config --get basecamp.projectid`);
$GitBchq = new GitBchq_Mini($BCHQ_APIKEY, $BCHQ_BASE_URL, $BCHQ_PROJECT_ID);
var_dump($GitBchq->getLastCommit());
{'fraction_non_alphanumeric': 0.15029761904761904, 'fraction_numerical': 0.003968253968253968, 'mean_word_length': 2.2058823529411766, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6368786', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1269, 'n_words': 234}