<commit_before><?php
/**
 * PHPCI - Continuous Integration for PHP
 *
 * @copyright    Copyright 2014, Block 8 Limited.
 * @license      https://github.com/Block8/PHPCI/blob/master/LICENSE.md
 * @link         https://www.phptesting.org/
 */

namespace PHPCI\Plugin;

use PHPCI\Builder;
use PHPCI\Helper\Lang;
use PHPCI\Model\Build;

/**
 * Git plugin.
 * @author       <NAME> <<EMAIL>>
 * @package      PHPCI
 * @subpackage   Plugins
 */
class Git implements \PHPCI\Plugin
{
    protected $phpci;
    protected $build;
    protected $actions = array();

    /**
     * Set up the plugin, configure options, etc.
     * @param Builder $phpci
     * @param Build $build
     * @param array $options
     */
    public function __construct(Builder $phpci, Build $build, array $options = array())
    {
        $this->phpci = $phpci;
        $this->build = $build;
        $this->actions = $options;
    }

    /**
     * Run the Git plugin.
     * @return bool
     */
    public function execute()
    {
        $buildPath = $this->phpci->buildPath;

        // Check if there are any actions to be run for the branch we're running on:
        if (!array_key_exists($this->build->getBranch(), $this->actions)) {
            return true;
        }

        // If there are, run them:
        $curdir = getcwd();
        chdir($buildPath);

        $success = true;
        foreach ($this->actions[$this->build->getBranch()] as $action => $options) {
            if (!$this->runAction($action, $options)) {
                $success = false;
                break;
            }
        }

        chdir($curdir);

        return $success;
    }

    /**
     * Determine which action to run, and run it.
     * @param $action
     * @param array $options
     * @return bool
     */
    protected function runAction($action, array $options = array())
    {
        switch ($action) {
            case 'merge':
                return $this->runMergeAction($options);

            case 'tag':
                return $this->runTagAction($options);

            case 'pull':
                return $this->runPullAction($options);

            case 'push':
                return $this->runPushAction($options);

            case 'run':
                return $this->runPluginAction($options);
        }


        return false;
    }

    /**
     * Handle a merge action.
     * @param $options
     * @return bool
     */
    protected function runMergeAction($options)
    {
        if (array_key_exists('branch', $options)) {
            $cmd = 'cd "%s" && git checkout %s && git merge "%s"';
            $path = $this->phpci->buildPath;
            return $this->phpci->executeCommand($cmd, $path, $options['branch'], $this->build->getBranch());
        }
    }

    /**
     * Handle a tag action.
     * @param $options
     * @return bool
     */
    protected function runTagAction($options)
    {
        $tagName = date('Ymd-His');
        $message = Lang::get('tag_created', date('Y-m-d H:i:s'));

        if (array_key_exists('name', $options)) {
            $tagName = $this->phpci->interpolate($options['name']);
        }

        if (array_key_exists('message', $options)) {
            $message = $this->phpci->interpolate($options['message']);
        }

        $cmd = 'git tag %s -m "%s"';
        return $this->phpci->executeCommand($cmd, $tagName, $message);
    }

    /**
     * Handle a pull action.
     * @param $options
     * @return bool
     */
    protected function runPullAction($options)
    {
        $branch = $this->build->getBranch();
        $remote = 'origin';

        if (array_key_exists('branch', $options)) {
            $branch = $this->phpci->interpolate($options['branch']);
        }

        if (array_key_exists('remote', $options)) {
            $remote = $this->phpci->interpolate($options['remote']);
        }

        return $this->phpci->executeCommand('git pull %s %s', $remote, $branch);
    }

    /**
     * Handle a push action.
     * @param $options
     * @return bool
     */
    protected function runPushAction($options)
    {
        $branch = $this->build->getBranch();
        $remote = 'origin';

        if (array_key_exists('branch', $options)) {
            $branch = $this->phpci->interpolate($options['branch']);
        }

        if (array_key_exists('remote', $options)) {
            $remote = $this->phpci->interpolate($options['remote']);
        }

        return $this->phpci->executeCommand('git push %s %s', $remote, $branch);
    }

    protected function runPluginAction($plugins)
    {
        $executor = $this->phpci->getPluginExecutor();

        foreach ($plugins as $plugin => $options) {
            $this->phpci->log(Lang::get('running_plugin', $plugin));

            // Try and execute it:
            if ($executor->executePlugin($plugin, $options)) {
                // Execution was successful:
                $this->phpci->logSuccess(Lang::get('plugin_success'));

                return true;
            } else {
                $this->phpci->logFailure(Lang::get('plugin_failed'));

                return false;
            }
        }

        return true;
    }
}<commit_msg>Fixed the git plugin only running one sub-plugin.<commit_after><?php
/**
 * PHPCI - Continuous Integration for PHP
 *
 * @copyright    Copyright 2014, Block 8 Limited.
 * @license      https://github.com/Block8/PHPCI/blob/master/LICENSE.md
 * @link         https://www.phptesting.org/
 */

namespace PHPCI\Plugin;

use PHPCI\Builder;
use PHPCI\Helper\Lang;
use PHPCI\Model\Build;

/**
 * Git plugin.
 * @author       <NAME> <<EMAIL>>
 * @package      PHPCI
 * @subpackage   Plugins
 */
class Git implements \PHPCI\Plugin
{
    protected $phpci;
    protected $build;
    protected $actions = array();

    /**
     * Set up the plugin, configure options, etc.
     * @param Builder $phpci
     * @param Build $build
     * @param array $options
     */
    public function __construct(Builder $phpci, Build $build, array $options = array())
    {
        $this->phpci = $phpci;
        $this->build = $build;
        $this->actions = $options;
    }

    /**
     * Run the Git plugin.
     * @return bool
     */
    public function execute()
    {
        $buildPath = $this->phpci->buildPath;

        // Check if there are any actions to be run for the branch we're running on:
        if (!array_key_exists($this->build->getBranch(), $this->actions)) {
            return true;
        }

        // If there are, run them:
        $curdir = getcwd();
        chdir($buildPath);

        $success = true;
        foreach ($this->actions[$this->build->getBranch()] as $action => $options) {
            if (!$this->runAction($action, $options)) {
                $success = false;
                break;
            }
        }

        chdir($curdir);

        return $success;
    }

    /**
     * Determine which action to run, and run it.
     * @param $action
     * @param array $options
     * @return bool
     */
    protected function runAction($action, array $options = array())
    {
        switch ($action) {
            case 'merge':
                return $this->runMergeAction($options);

            case 'tag':
                return $this->runTagAction($options);

            case 'pull':
                return $this->runPullAction($options);

            case 'push':
                return $this->runPushAction($options);

            case 'run':
                return $this->runPluginAction($options);
        }


        return false;
    }

    /**
     * Handle a merge action.
     * @param $options
     * @return bool
     */
    protected function runMergeAction($options)
    {
        if (array_key_exists('branch', $options)) {
            $cmd = 'cd "%s" && git checkout %s && git merge "%s"';
            $path = $this->phpci->buildPath;
            return $this->phpci->executeCommand($cmd, $path, $options['branch'], $this->build->getBranch());
        }
    }

    /**
     * Handle a tag action.
     * @param $options
     * @return bool
     */
    protected function runTagAction($options)
    {
        $tagName = date('Ymd-His');
        $message = Lang::get('tag_created', date('Y-m-d H:i:s'));

        if (array_key_exists('name', $options)) {
            $tagName = $this->phpci->interpolate($options['name']);
        }

        if (array_key_exists('message', $options)) {
            $message = $this->phpci->interpolate($options['message']);
        }

        $cmd = 'git tag %s -m "%s"';
        return $this->phpci->executeCommand($cmd, $tagName, $message);
    }

    /**
     * Handle a pull action.
     * @param $options
     * @return bool
     */
    protected function runPullAction($options)
    {
        $branch = $this->build->getBranch();
        $remote = 'origin';

        if (array_key_exists('branch', $options)) {
            $branch = $this->phpci->interpolate($options['branch']);
        }

        if (array_key_exists('remote', $options)) {
            $remote = $this->phpci->interpolate($options['remote']);
        }

        return $this->phpci->executeCommand('git pull %s %s', $remote, $branch);
    }

    /**
     * Handle a push action.
     * @param $options
     * @return bool
     */
    protected function runPushAction($options)
    {
        $branch = $this->build->getBranch();
        $remote = 'origin';

        if (array_key_exists('branch', $options)) {
            $branch = $this->phpci->interpolate($options['branch']);
        }

        if (array_key_exists('remote', $options)) {
            $remote = $this->phpci->interpolate($options['remote']);
        }

        return $this->phpci->executeCommand('git push %s %s', $remote, $branch);
    }

    protected function runPluginAction($plugins)
    {
        $executor = $this->phpci->getPluginExecutor();
        $result = true;

        foreach ($plugins as $plugin => $options) {
            $this->phpci->log(Lang::get('running_plugin', $plugin));

            // Try and execute it:
            if ($executor->executePlugin($plugin, $options)) {
                // Execution was successful:
                $this->phpci->logSuccess(Lang::get('plugin_success'));

                $result = true;
            } else {
                $this->phpci->logFailure(Lang::get('plugin_failed'));

                $result = false;
            }
        }

        return $result;
    }
}
{'fraction_non_alphanumeric': 0.15270983213429257, 'fraction_numerical': 0.0011510791366906475, 'mean_word_length': 1.9377289377289377, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 121, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '2929717', 'n_tokens_mistral': 3074, 'n_tokens_neox': 2972, 'n_words': 683}