public function run()

in src/workflow/ArcanistDiffWorkflow.php [468:721]


  public function run() {
    $this->console = PhutilConsole::getConsole();
    // UBER CODE
    $this->uberRefProvider = new UberRefProvider(
      $this->getConfigurationManager()->getConfigFromAnySource('uber.arcanist.use_non_tag_refs', false)
    );
    // UBER CODE END

    $this->runRepositoryAPISetup();

    if ($this->getArgument('no-diff')) {
      $this->removeScratchFile('diff-result.json');
      $data = $this->runLintUnit();
      $this->writeScratchJSONFile('diff-result.json', $data);
      return 0;
    }

    $this->runDiffSetupBasics();

    $commit_message = $this->buildCommitMessage();

    $this->dispatchEvent(
      ArcanistEventType::TYPE_DIFF_DIDBUILDMESSAGE,
      array(
        'message' => $commit_message,
      ));

    $diff_spec = $this->buildDiffSpecification(); // UBER CODE
    $shouldTagWithAutoland = false; // UBER CODE

    if (!$this->shouldOnlyCreateDiff()) {
      $revision = $this->buildRevisionFromCommitMessage($commit_message);
      $this->attachJiraIssues($revision, $diff_spec, // UBER CODE
                              $commit_message);      // UBER CODE
      $shouldTagWithAutoland = $this->shouldTagWithAutoland($revision); // UBER CODE
    }

    $this->runCheckPromptResolveScripts();

    $server = $this->console->getServer();
    $server->setHandler(array($this, 'handleServerMessage'));
    $data = $this->runLintUnit();

    $lint_result = $data['lintResult'];
    $this->unresolvedLint = $data['unresolvedLint'];
    $unit_result = $data['unitResult'];
    $this->testResults = $data['testResults'];

    if ($this->getArgument('nolint')) {
      $this->excuses['lint'] = $this->getSkipExcuse(
        pht('Provide explanation for skipping lint or press Enter to abort:'),
        'lint-excuses');
    }

    if ($this->getArgument('nounit')) {
      $this->excuses['unit'] = $this->getSkipExcuse(
        pht(
          'Provide explanation for skipping unit tests '.
          'or press Enter to abort:'),
        'unit-excuses');
    }

    $changes = $this->generateChanges();
    if (!$changes) {
      throw new ArcanistUsageException(
        pht('There are no changes to generate a diff from!'));
    }

    $diff_spec = array(
      'changes' => mpull($changes, 'toDictionary'),
      'lintStatus' => $this->getLintStatus($lint_result),
      'unitStatus' => $this->getUnitStatus($unit_result),
    ) + $diff_spec; // UBER CODE

    $conduit = $this->getConduit();
    $diff_info = $conduit->callMethodSynchronous(
      'differential.creatediff',
      $diff_spec);

    $this->diffID = $diff_info['diffid'];

    $event = $this->dispatchEvent(
      ArcanistEventType::TYPE_DIFF_WASCREATED,
      array(
        'diffID' => $diff_info['diffid'],
        'lintResult' => $lint_result,
        'unitResult' => $unit_result,
      ));

    $this->submitChangesToStagingArea($this->diffID);

    $phid = idx($diff_info, 'phid');
    if ($phid) {
      $this->hitAutotargets = $this->updateAutotargets(
        $phid,
        $unit_result);
    }

    $this->updateLintDiffProperty();
    $this->updateUnitDiffProperty();
    $this->updateLocalDiffProperty();
    $this->updateOntoDiffProperty();
    $this->resolveDiffPropertyUpdates();

    $output_json = $this->getArgument('json');

    if ($this->shouldOnlyCreateDiff()) {
      if (!$output_json) {
        echo phutil_console_format(
          "%s\n        **%s** __%s__\n\n",
          pht('Created a new Differential diff:'),
          pht('Diff URI:'),
          $diff_info['uri']);
      } else {
        $human = ob_get_clean();
        echo json_encode(array(
          'diffURI' => $diff_info['uri'],
          'diffID'  => $this->getDiffID(),
          'human'   => $human,
        ))."\n";
        ob_start();
      }

      if ($this->shouldOpenCreatedObjectsInBrowser()) {
        $this->openURIsInBrowser(array($diff_info['uri']));
      }
    } else {
      $revision['diffid'] = $this->getDiffID();
      // UBER CODE
      if ($this->getArgument('plan-changes')) {
          $revision['fields']['plan-changes'] = true;
      }
      $wip = (bool)preg_match('/\bwip\b/i', $revision['fields']['title']);
      // UBER CODE END
      if ($commit_message->getRevisionID()) {
        // UBER CODE
        if ($wip && !idx($revision['fields'], 'plan-changes', false)) {
          // fetch revision status
          $rev = $this->getConduit()->callMethodSynchronous(
          'differential.query',
          array(
            'ids' => array($commit_message->getRevisionID()),
          ));
          $rev = head($rev);
          if (idx($rev, 'statusName', false) == 'Changes Planned') {
            $this->writeInfo('Changes Planned', phutil_console_format(
              pht('Keyword "wip" found in title and Differential Revision D%s '.
                  'is in <fg:green>Changes Planned</fg> status, keeping same '.
                  'status', $commit_message->getRevisionID())));
            $revision['fields']['plan-changes'] = true;
          }
        }
        // UBER CODE END
        $result = $conduit->callMethodSynchronous(
          'differential.updaterevision',
          $revision);

        foreach (array('edit-messages.json', 'update-messages.json') as $file) {
          $messages = $this->readScratchJSONFile($file);
          unset($messages[$revision['id']]);
          $this->writeScratchJSONFile($file, $messages);
        }

        echo pht('Updated an existing Differential revision:')."\n";
      } else {
        // UBER CODE
        if ($wip && !idx($revision['fields'], 'plan-changes', false)) {
          $prompt = 'Keyword "wip" found in revision title, do you want to '.
            'set differential to <fg:green>Changes planned</fg> status which '.
            'will not send notifications to subscribers and reviewers of this '.
            'change? You can later change status via Web UI or by changing '.
            'change title during next revision';
          if (phutil_console_confirm(phutil_console_format($prompt), false)) {
            $revision['fields']['plan-changes'] = true;
          }
        }
        // UBER CODE END
        $revision = $this->dispatchWillCreateRevisionEvent($revision);

        $result = $conduit->callMethodSynchronous(
          'differential.createrevision',
          $revision);

        $revised_message = $conduit->callMethodSynchronous(
          'differential.getcommitmessage',
          array(
            'revision_id' => $result['revisionid'],
          ));

        if ($this->shouldAmend()) {
          $repository_api = $this->getRepositoryAPI();
          if ($repository_api->supportsAmend()) {
            echo pht('Updating commit message...')."\n";
            $repository_api->amendCommit($revised_message);
          } else {
            echo pht(
              'Commit message was not amended. Amending commit message is '.
              'only supported in git and hg (version 2.2 or newer)');
          }
        }

        echo pht('Created a new Differential revision:')."\n";
      }

      $uri = $result['uri'];
      echo phutil_console_format(
        "        **%s** __%s__\n\n",
        pht('Revision URI:'),
        $uri);

      if ($this->getArgument('plan-changes')) {
        $conduit->callMethodSynchronous(
          'differential.createcomment',
          array(
            'revision_id' => $result['revisionid'],
            'action' => 'rethink',
          ));
        echo pht('Planned changes to the revision.')."\n";
      }

      if ($this->shouldOpenCreatedObjectsInBrowser()) {
        $this->openURIsInBrowser(array($uri));
      }
      // UBER CODE
      if (idx($revision, 'id')) {
        $this->removeScratchFile(sprintf('D%s-jira-issues.json', $revision['id']));
      }

      if ($shouldTagWithAutoland) {
        $tagResult = $conduit->callMethodSynchronous('differential.revision.edit',
          array(
            'objectIdentifier' => $result['revisionid'],
            'transactions' => array(
              array('type' => 'projects.add', 'value' => array($this->autolandProjectPhid)),
            ),
        ));
      }
      // UBER CODE END
    }

    echo pht('Included changes:')."\n";
    foreach ($changes as $change) {
      echo '  '.$change->renderTextSummary()."\n";
    }

    if ($output_json) {
      ob_get_clean();
    }

    $this->removeScratchFile('create-message');
    $this->removeScratchFile('create-message-jira-issues.json'); // UBER CODE

    return 0;
  }