3 final class PhabricatorRepositoryManagementHintWorkflow
4 extends PhabricatorRepositoryManagementWorkflow
{
6 protected function didConstruct() {
9 ->setExamples('**hint** [options] ...')
12 'Write hints about unusual (rewritten or unreadable) commits.'))
13 ->setArguments(array());
16 public function execute(PhutilArgumentParser
$args) {
17 $viewer = $this->getViewer();
21 pht('Reading list of hints from stdin...'));
23 $hints = file_get_contents('php://stdin');
24 if ($hints === false) {
25 throw new PhutilArgumentUsageException(pht('Failed to read stdin.'));
29 $hints = phutil_json_decode($hints);
30 } catch (Exception
$ex) {
31 throw new PhutilArgumentUsageException(
33 'Expected a list of hints in JSON format: %s',
37 $repositories = array();
38 foreach ($hints as $idx => $hint) {
39 if (!is_array($hint)) {
40 throw new PhutilArgumentUsageException(
42 'Each item in the list of hints should be a JSON object, but '.
43 'the item at index "%s" is not.',
48 PhutilTypeSpec
::checkMap(
51 'repository' => 'string|int',
53 'new' => 'optional string|null',
56 } catch (Exception
$ex) {
57 throw new PhutilArgumentUsageException(
59 'Unexpected hint format at index "%s": %s',
64 $repository_identifier = $hint['repository'];
65 $repository = idx($repositories, $repository_identifier);
67 $repository = id(new PhabricatorRepositoryQuery())
69 ->withIdentifiers(array($repository_identifier))
72 throw new PhutilArgumentUsageException(
74 'Repository identifier "%s" (in hint at index "%s") does not '.
75 'identify a valid repository.',
76 $repository_identifier,
80 $repositories[$repository_identifier] = $repository;
83 PhabricatorRepositoryCommitHint
::updateHint(
84 $repository->getPHID(),
92 'Updated hint for "%s".',