Differential D14280 Diff 34471 src/applications/drydock/operation/DrydockLandRepositoryOperation.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/operation/DrydockLandRepositoryOperation.php
| Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if ($object instanceof DifferentialRevision) { | ||||
| } | } | ||||
| $cmd[] = 'git fetch --no-tags -- %s +%s:%s'; | $cmd[] = 'git fetch --no-tags -- %s +%s:%s'; | ||||
| $arg[] = $repository->getStagingURI(); | $arg[] = $repository->getStagingURI(); | ||||
| $arg[] = $diff->getStagingRef(); | $arg[] = $diff->getStagingRef(); | ||||
| $arg[] = $diff->getStagingRef(); | $arg[] = $diff->getStagingRef(); | ||||
| $merge_src = $diff->getStagingRef(); | $merge_src = $diff->getStagingRef(); | ||||
| $dict = $diff->getDiffAuthorshipDict(); | |||||
| $author_name = idx($dict, 'authorName'); | |||||
| $author_email = idx($dict, 'authorEmail'); | |||||
| $api_method = 'differential.getcommitmessage'; | |||||
| $api_params = array( | |||||
| 'revision_id' => $revision->getID(), | |||||
| ); | |||||
| $commit_message = id(new ConduitCall($api_method, $api_params)) | |||||
| ->setUser($viewer) | |||||
| ->execute(); | |||||
| } else { | } else { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Invalid or unknown object ("%s") for land operation, expected '. | 'Invalid or unknown object ("%s") for land operation, expected '. | ||||
| 'Differential Revision.', | 'Differential Revision.', | ||||
| $operation->getObjectPHID())); | $operation->getObjectPHID())); | ||||
| } | } | ||||
| $target = $operation->getRepositoryTarget(); | $target = $operation->getRepositoryTarget(); | ||||
| list($type, $name) = explode(':', $target, 2); | list($type, $name) = explode(':', $target, 2); | ||||
| switch ($type) { | switch ($type) { | ||||
| case 'branch': | case 'branch': | ||||
| $push_dst = 'refs/heads/'.$name; | $push_dst = 'refs/heads/'.$name; | ||||
| $merge_dst = 'refs/remotes/origin/'.$name; | $merge_dst = 'refs/remotes/origin/'.$name; | ||||
| break; | break; | ||||
| default: | default: | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Unknown repository operation target type "%s" (in target "%s").', | 'Unknown repository operation target type "%s" (in target "%s").', | ||||
| $type, | $type, | ||||
| $target)); | $target)); | ||||
| } | } | ||||
| $committer_info = $this->getCommitterInfo($operation); | |||||
| $cmd[] = 'git checkout %s'; | $cmd[] = 'git checkout %s'; | ||||
| $arg[] = $merge_dst; | $arg[] = $merge_dst; | ||||
| $cmd[] = 'git merge --no-stat --squash --ff-only -- %s'; | $cmd[] = 'git merge --no-stat --squash --ff-only -- %s'; | ||||
| $arg[] = $merge_src; | $arg[] = $merge_src; | ||||
| $cmd[] = 'git -c user.name=%s -c user.email=%s commit --author %s -m %s'; | $cmd[] = 'git -c user.name=%s -c user.email=%s commit --author %s -m %s'; | ||||
| $arg[] = 'autocommitter'; | |||||
| $arg[] = 'autocommitter@example.com'; | $arg[] = $committer_info['name']; | ||||
| $arg[] = 'autoauthor <autoauthor@example.com>'; | $arg[] = $committer_info['email']; | ||||
| $arg[] = pht('(Automerge!)'); | |||||
| $arg[] = "{$author_name} <{$author_email}>"; | |||||
| $arg[] = $commit_message; | |||||
| $cmd[] = 'git push origin -- %s:%s'; | $cmd[] = 'git push origin -- %s:%s'; | ||||
| $arg[] = 'HEAD'; | $arg[] = 'HEAD'; | ||||
| $arg[] = $push_dst; | $arg[] = $push_dst; | ||||
| $cmd = implode(' && ', $cmd); | $cmd = implode(' && ', $cmd); | ||||
| $argv = array_merge(array($cmd), $arg); | $argv = array_merge(array($cmd), $arg); | ||||
| $result = call_user_func_array( | $result = call_user_func_array( | ||||
| array($interface, 'execx'), | array($interface, 'execx'), | ||||
| $argv); | $argv); | ||||
| } | } | ||||
| private function getCommitterInfo(DrydockRepositoryOperation $operation) { | |||||
| $viewer = $this->getViewer(); | |||||
| $committer_name = null; | |||||
| $author_phid = $operation->getAuthorPHID(); | |||||
| $object = id(new PhabricatorObjectQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withPHIDs(array($author_phid)) | |||||
| ->executeOne(); | |||||
| if ($object) { | |||||
| if ($object instanceof PhabricatorUser) { | |||||
| $committer_name = $object->getUsername(); | |||||
| } | |||||
| } | |||||
| if (!strlen($committer_name)) { | |||||
| $committer_name = pht('autocommitter'); | |||||
| } | |||||
| // TODO: Probably let users choose a VCS email address in settings. For | |||||
| // now just make something up so we don't leak anyone's stuff. | |||||
| return array( | |||||
| 'name' => $committer_name, | |||||
| 'email' => 'autocommitter@example.com', | |||||
| ); | |||||
| } | |||||
| } | } | ||||