|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright 2011 Facebook, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +class ConduitAPI_differential_creatediff_Method extends ConduitAPIMethod { |
| 20 | + |
| 21 | + public function getMethodDescription() { |
| 22 | + return "Create a new Differential diff."; |
| 23 | + } |
| 24 | + |
| 25 | + public function defineParamTypes() { |
| 26 | + return array( |
| 27 | + 'changes' => 'required list<dict>', |
| 28 | + 'sourceMachine' => 'required string', |
| 29 | + 'sourcePath' => 'required string', |
| 30 | + 'branch' => 'required string', |
| 31 | + 'sourceControlSystem' => 'required enum<svn, git>', |
| 32 | + 'sourceControlPath' => 'required string', |
| 33 | + 'sourceControlBaseRevision' => 'required string', |
| 34 | + 'parentRevisionID' => 'optional revisionid', |
| 35 | + 'creationMethod' => 'optional string', |
| 36 | + 'ownerPHID' => 'optional phid', |
| 37 | + 'arcanistProject' => 'optional string', |
| 38 | + 'lintStatus' => |
| 39 | + 'required enum<none, skip, okay, warn, fail>', |
| 40 | + 'unitStatus' => |
| 41 | + 'required enum<none, skip, okay, warn, fail>', |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + public function defineReturnType() { |
| 46 | + return 'nonempty dict'; |
| 47 | + } |
| 48 | + |
| 49 | + public function defineErrorTypes() { |
| 50 | + return array( |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + protected function execute(ConduitAPIRequest $request) { |
| 55 | + $change_data = $request->getValue('changes'); |
| 56 | + |
| 57 | + $changes = array(); |
| 58 | + foreach ($change_data as $dict) { |
| 59 | + $changes[] = ArcanistDiffChange::newFromDictionary($dict); |
| 60 | + } |
| 61 | + |
| 62 | + $diff = DifferentialDiff::newFromRawChanges($changes); |
| 63 | + $diff->setSourcePath($request->getValue('sourcePath')); |
| 64 | + $diff->setSourceMachine($request->getValue('sourceMachine')); |
| 65 | + |
| 66 | + $diff->setBranch($request->getValue('branch')); |
| 67 | + $diff->setCreationMethod($request->getValue('creationMethod')); |
| 68 | + $diff->setOwnerPHID($request->getValue('ownerPHID')); |
| 69 | + |
| 70 | + $parent_id = $request->getValue('parentRevisionID'); |
| 71 | + if ($parent_id) { |
| 72 | + $parent_rev = id(new DifferentialRevision())->load($parent_id); |
| 73 | + if ($parent_rev) { |
| 74 | + if ($parent_rev->getStatus() != DifferentialRevisionStatus::COMMITTED) { |
| 75 | + $diff->setParentRevisionID($parent_id); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + $system = $request->getValue('sourceControlSystem'); |
| 81 | + $diff->setSourceControlSystem($system); |
| 82 | + $diff->setSourceControlPath($request->getValue('sourceControlPath')); |
| 83 | + $diff->setSourceControlBaseRevision( |
| 84 | + $request->getValue('sourceControlBaseRevision')); |
| 85 | + |
| 86 | + $diff->setArcanistProject($request->getValue('arcanistProject')); |
| 87 | + |
| 88 | + switch ($request->getValue('lintStatus')) { |
| 89 | + case 'skip': |
| 90 | + $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP); |
| 91 | + break; |
| 92 | + case 'okay': |
| 93 | + $diff->setLintStatus(DifferentialLintStatus::LINT_OKAY); |
| 94 | + break; |
| 95 | + case 'warn': |
| 96 | + $diff->setLintStatus(DifferentialLintStatus::LINT_WARN); |
| 97 | + break; |
| 98 | + case 'fail': |
| 99 | + $diff->setLintStatus(DifferentialLintStatus::LINT_FAIL); |
| 100 | + break; |
| 101 | + case 'none': |
| 102 | + default: |
| 103 | + $diff->setLintStatus(DifferentialLintStatus::LINT_NONE); |
| 104 | + break; |
| 105 | + } |
| 106 | + |
| 107 | + switch ($request->getValue('unitStatus')) { |
| 108 | + case 'skip': |
| 109 | + $diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP); |
| 110 | + break; |
| 111 | + case 'okay': |
| 112 | + $diff->setUnitStatus(DifferentialUnitStatus::UNIT_OKAY); |
| 113 | + break; |
| 114 | + case 'warn': |
| 115 | + $diff->setUnitStatus(DifferentialUnitStatus::UNIT_WARN); |
| 116 | + break; |
| 117 | + case 'fail': |
| 118 | + $diff->setUnitStatus(DifferentialUnitStatus::UNIT_FAIL); |
| 119 | + break; |
| 120 | + case 'none': |
| 121 | + default: |
| 122 | + $diff->setUnitStatus(DifferentialUnitStatus::UNIT_NONE); |
| 123 | + break; |
| 124 | + } |
| 125 | + |
| 126 | + $diff->save(); |
| 127 | + |
| 128 | + return array( |
| 129 | + 'diffid' => $diff->getID(), |
| 130 | + 'uri' => '?'//$diff->getURI(), |
| 131 | + ); |
| 132 | + } |
| 133 | + |
| 134 | +} |
0 commit comments