From 3aed39b8b072c8bfa89b3f45183dfa126600ff1d Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 17 May 2016 17:41:20 -0700 Subject: [PATCH] Fix an issue with serializing reviewers over the wire Fixes T10981. Ref T10939. `arc` currently has some odd, hard-coded checks (missing reviewers, all reviewers away) that depend on the field value being in a certain format. The recent changes swapped the field value from scalars (PHIDs) to dictionaries and broke this workflow. It worked fine in testing because we apply these checks very inconsistently (not on update or `--edit`). To get around this for now, serialize into "PHID!" and then unserialize on the other side. This is icky but keeps us from needing to require an `arc` upgrade. These checks are generally bad news and should move to the server side in the long run (T4631). (This probably prevents clean `arc diff`, so I'm just cowboy committing it.) Auditors: chad --- .../DifferentialReviewersField.php | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/applications/differential/customfield/DifferentialReviewersField.php b/src/applications/differential/customfield/DifferentialReviewersField.php index 1037c16909..d23dac53d9 100644 --- a/src/applications/differential/customfield/DifferentialReviewersField.php +++ b/src/applications/differential/customfield/DifferentialReviewersField.php @@ -180,7 +180,7 @@ final class DifferentialReviewersField } public function parseValueFromCommitMessage($value) { - return $this->parseObjectList( + $results = $this->parseObjectList( $value, array( PhabricatorPeopleUserPHIDType::TYPECONST, @@ -189,6 +189,8 @@ final class DifferentialReviewersField ), false, array('!')); + + return $this->flattenReviewers($results); } public function getRequiredHandlePHIDsForCommitMessage() { @@ -196,6 +198,8 @@ final class DifferentialReviewersField } public function readValueFromCommitMessage($value) { + $value = $this->inflateReviewers($value); + $reviewers = array(); foreach ($value as $spec) { $phid = $spec['phid']; @@ -287,4 +291,36 @@ final class DifferentialReviewersField ); } + private function flattenReviewers(array $values) { + // NOTE: For now, `arc` relies on this field returning only scalars, so we + // need to reduce the results into scalars. See T10981. + $result = array(); + + foreach ($values as $value) { + $result[] = $value['phid'].implode('', array_keys($value['suffixes'])); + } + + return $result; + } + + private function inflateReviewers(array $values) { + $result = array(); + + foreach ($values as $value) { + if (substr($value, -1) == '!') { + $value = substr($value, 0, -1); + $suffixes = array('!' => '!'); + } else { + $suffixes = array(); + } + + $result[] = array( + 'phid' => $value, + 'suffixes' => $suffixes, + ); + } + + return $result; + } + }