Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / xaction / PhabricatorRepositoryFetchRefsTransaction.php
blob2965b0b742966272ba53b2d4e38fc2c46c182bcd
1 <?php
3 final class PhabricatorRepositoryFetchRefsTransaction
4 extends PhabricatorRepositoryTransactionType {
6 const TRANSACTIONTYPE = 'fetch-refs';
8 public function generateOldValue($object) {
9 return $object->getFetchRules();
12 public function applyInternalEffects($object, $value) {
13 $object->setFetchRules($value);
16 public function getTitle() {
17 $old = $this->getOldValue();
18 $new = $this->getNewValue();
20 if (!$new) {
21 return pht(
22 '%s set this repository to fetch all refs.',
23 $this->renderAuthor());
24 } else if (!$old) {
25 return pht(
26 '%s set this repository to fetch refs: %s.',
27 $this->renderAuthor(),
28 $this->renderValue(implode(', ', $new)));
29 } else {
30 return pht(
31 '%s changed fetched refs from %s to %s.',
32 $this->renderAuthor(),
33 $this->renderValue(implode(', ', $old)),
34 $this->renderValue(implode(', ', $new)));
38 public function validateTransactions($object, array $xactions) {
39 $errors = array();
41 foreach ($xactions as $xaction) {
42 $new_value = $xaction->getNewValue();
44 if (!is_array($new_value) || !phutil_is_natural_list($new_value)) {
45 $errors[] = $this->newInvalidError(
46 pht(
47 'Fetch rules must be a list of strings, got "%s".',
48 phutil_describe_type($new_value)),
49 $xaction);
50 continue;
53 foreach ($new_value as $idx => $rule) {
54 if (!is_string($rule)) {
55 $errors[] = $this->newInvalidError(
56 pht(
57 'Fetch rule (at index "%s") must be a string, got "%s".',
58 $idx,
59 phutil_describe_type($rule)),
60 $xaction);
61 continue;
64 if (!strlen($rule)) {
65 $errors[] = $this->newInvalidError(
66 pht(
67 'Fetch rule (at index "%s") is empty. Fetch rules must '.
68 'contain text.',
69 $idx),
70 $xaction);
71 continue;
74 // Since we fetch ref "X" as "+X:X", don't allow rules to include
75 // colons. This is specific to Git and may not be relevant if
76 // Mercurial repositories eventually get fetch rules.
77 if (preg_match('/:/', $rule)) {
78 $errors[] = $this->newInvalidError(
79 pht(
80 'Fetch rule ("%s", at index "%s") is invalid: fetch rules '.
81 'must not contain colons.',
82 $rule,
83 $idx),
84 $xaction);
85 continue;
91 return $errors;