Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / management / PhabricatorRepositoryManagementHintWorkflow.php
bloba56d9a7f4e344fd5eac8463ae7854cea78e2b951
1 <?php
3 final class PhabricatorRepositoryManagementHintWorkflow
4 extends PhabricatorRepositoryManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('hint')
9 ->setExamples('**hint** [options] ...')
10 ->setSynopsis(
11 pht(
12 'Write hints about unusual (rewritten or unreadable) commits.'))
13 ->setArguments(array());
16 public function execute(PhutilArgumentParser $args) {
17 $viewer = $this->getViewer();
19 echo tsprintf(
20 "%s\n",
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.'));
28 try {
29 $hints = phutil_json_decode($hints);
30 } catch (Exception $ex) {
31 throw new PhutilArgumentUsageException(
32 pht(
33 'Expected a list of hints in JSON format: %s',
34 $ex->getMessage()));
37 $repositories = array();
38 foreach ($hints as $idx => $hint) {
39 if (!is_array($hint)) {
40 throw new PhutilArgumentUsageException(
41 pht(
42 'Each item in the list of hints should be a JSON object, but '.
43 'the item at index "%s" is not.',
44 $idx));
47 try {
48 PhutilTypeSpec::checkMap(
49 $hint,
50 array(
51 'repository' => 'string|int',
52 'old' => 'string',
53 'new' => 'optional string|null',
54 'hint' => 'string',
55 ));
56 } catch (Exception $ex) {
57 throw new PhutilArgumentUsageException(
58 pht(
59 'Unexpected hint format at index "%s": %s',
60 $idx,
61 $ex->getMessage()));
64 $repository_identifier = $hint['repository'];
65 $repository = idx($repositories, $repository_identifier);
66 if (!$repository) {
67 $repository = id(new PhabricatorRepositoryQuery())
68 ->setViewer($viewer)
69 ->withIdentifiers(array($repository_identifier))
70 ->executeOne();
71 if (!$repository) {
72 throw new PhutilArgumentUsageException(
73 pht(
74 'Repository identifier "%s" (in hint at index "%s") does not '.
75 'identify a valid repository.',
76 $repository_identifier,
77 $idx));
80 $repositories[$repository_identifier] = $repository;
83 PhabricatorRepositoryCommitHint::updateHint(
84 $repository->getPHID(),
85 $hint['old'],
86 idx($hint, 'new'),
87 $hint['hint']);
89 echo tsprintf(
90 "%s\n",
91 pht(
92 'Updated hint for "%s".',
93 $hint['old']));