[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DifferentialLandingToHostedMercurial 4 extends DifferentialLandingStrategy { 5 6 public function processLandRequest( 7 AphrontRequest $request, 8 DifferentialRevision $revision, 9 PhabricatorRepository $repository) { 10 11 $viewer = $request->getUser(); 12 13 $workspace = $this->getMercurialWorkspace($repository); 14 15 try { 16 $this->commitRevisionToWorkspace( 17 $revision, 18 $workspace, 19 $viewer); 20 } catch (Exception $e) { 21 throw new PhutilProxyException( 22 'Failed to commit patch', 23 $e); 24 } 25 26 try { 27 $this->pushWorkspaceRepository( 28 $repository, 29 $workspace, 30 $viewer); 31 } catch (Exception $e) { 32 throw new PhutilProxyException( 33 'Failed to push changes upstream', 34 $e); 35 } 36 } 37 38 public function commitRevisionToWorkspace( 39 DifferentialRevision $revision, 40 ArcanistRepositoryAPI $workspace, 41 PhabricatorUser $user) { 42 43 $diff_id = $revision->loadActiveDiff()->getID(); 44 45 $call = new ConduitCall( 46 'differential.getrawdiff', 47 array( 48 'diffID' => $diff_id, 49 )); 50 51 $call->setUser($user); 52 $raw_diff = $call->execute(); 53 54 $future = $workspace->execFutureLocal('patch --no-commit -'); 55 $future->write($raw_diff); 56 $future->resolvex(); 57 58 $workspace->reloadWorkingCopy(); 59 60 $call = new ConduitCall( 61 'differential.getcommitmessage', 62 array( 63 'revision_id' => $revision->getID(), 64 )); 65 66 $call->setUser($user); 67 $message = $call->execute(); 68 69 $author = id(new PhabricatorUser())->loadOneWhere( 70 'phid = %s', 71 $revision->getAuthorPHID()); 72 73 $author_string = sprintf( 74 '%s <%s>', 75 $author->getRealName(), 76 $author->loadPrimaryEmailAddress()); 77 $author_date = $revision->getDateCreated(); 78 79 $workspace->execxLocal( 80 'commit --date=%s --user=%s '. 81 '--message=%s', 82 $author_date.' 0', 83 $author_string, 84 $message); 85 } 86 87 88 public function pushWorkspaceRepository( 89 PhabricatorRepository $repository, 90 ArcanistRepositoryAPI $workspace, 91 PhabricatorUser $user) { 92 93 $workspace->execxLocal('push -b default'); 94 } 95 96 public function createMenuItem( 97 PhabricatorUser $viewer, 98 DifferentialRevision $revision, 99 PhabricatorRepository $repository) { 100 101 $vcs = $repository->getVersionControlSystem(); 102 if ($vcs !== PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL) { 103 return; 104 } 105 106 if (!$repository->isHosted()) { 107 return; 108 } 109 110 return $this->createActionView( 111 $revision, 112 pht('Land to Hosted Repository')); 113 } 114 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |