<commit_before><?php

namespace pub\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use vierbergenlars\SemVer\version;


class NewReleaseCommand extends Command {
  const MASTER_BRANCH = 'master';

  protected function configure() {
    $this->setName('new-release')
      ->setDescription('Creates a new version of publisher and tags the release.')
      ->addArgument(
        'increment',
        InputArgument::REQUIRED,
        'major|minor|patch|x.y.z'
      )
      ->addOption(
        'push',
        'p',
        InputOption::VALUE_NONE,
        'If set we will push the new tag to github.'
      );
    }

  /**
   * Process the New Release command.
   *
   * - Update the version.php file
   * - Commit the change and tag it
   * - If the --push option is used, push the change to Acquia
   *
   * This command assumes you are running it from the root of the repository.
   * Additionally, this command makes changes to the master branch.
   */
  protected function execute(InputInterface $input, OutputInterface $output) {
    // Checkout the master branch.
    $process = new Process('git checkout ' . self::MASTER_BRANCH);
    $process->run();
    if (!$process->isSuccessful()) {
      throw new \RuntimeException($process->getErrorOutput());
    }

    // @TODO: Figure out how to make this work without hard-coding the path to version.php.
    $version_filename = 'docroot/version.php';
    require_once $version_filename;

    // Determine the new version number.
    $increment = $input->getArgument('increment');
    try {
      // This will succeed when a specific version number is provided, otherwise
      // an exception will be thrown and the "catch" is used.
      $version = new version($increment);
      $version_number = $version->getVersion();
    } catch(\Exception $e) {
      $current_version = new version(PUBLISHER_VERSION);
      $version_number = $current_version->inc($increment);
    }

    // Update version.php.
    $this->updateVersionFile($version_filename, $version_number);<commit_msg>Adding an exception when version.php cannot be found<commit_after><?php

namespace pub\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use vierbergenlars\SemVer\version;


class NewReleaseCommand extends Command {
  const MASTER_BRANCH = 'master';

  protected function configure() {
    $this->setName('new-release')
      ->setDescription('Creates a new version of publisher and tags the release.')
      ->addArgument(
        'increment',
        InputArgument::REQUIRED,
        'major|minor|patch|x.y.z'
      )
      ->addOption(
        'push',
        'p',
        InputOption::VALUE_NONE,
        'If set we will push the new tag to github.'
      );
    }

  /**
   * Process the New Release command.
   *
   * - Update the version.php file
   * - Commit the change and tag it
   * - If the --push option is used, push the change to Acquia
   *
   * This command assumes you are running it from the root of the repository.
   * Additionally, this command makes changes to the master branch.
   */
  protected function execute(InputInterface $input, OutputInterface $output) {
    // Checkout the master branch.
    $process = new Process('git checkout ' . self::MASTER_BRANCH);
    $process->run();
    if (!$process->isSuccessful()) {
      throw new \RuntimeException($process->getErrorOutput());
    }

    // @TODO: Figure out how to make this work without hard-coding the path to version.php.
    $version_filename = 'docroot/version.php';
    if (!file_exists($version_filename)) {
      throw new \Exception("The version.php file could not be found.");
    }
    require_once $version_filename;

    // Determine the new version number.
    $increment = $input->getArgument('increment');
    try {
      // This will succeed when a specific version number is provided, otherwise
      // an exception will be thrown and the "catch" is used.
      $version = new version($increment);
      $version_number = $version->getVersion();
    } catch(\Exception $e) {
      $current_version = new version(PUBLISHER_VERSION);
      $version_number = $current_version->inc($increment);
    }

    // Update version.php.
    $this->updateVersionFile($version_filename, $version_number);
{'fraction_non_alphanumeric': 0.10963244613434728, 'fraction_numerical': 0.0, 'mean_word_length': 3.1865605658709106, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '3937461', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1312, 'n_words': 394}