Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialRevisionLandController extends DifferentialController {
|
|
|
|
|
|
|
|
private $revisionID;
|
|
|
|
private $strategyClass;
|
|
|
|
private $pushStrategy;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->revisionID = $data['id'];
|
|
|
|
$this->strategyClass = $data['strategy'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$revision_id = $this->revisionID;
|
|
|
|
|
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->withIDs(array($revision_id))
|
|
|
|
->setViewer($viewer)
|
|
|
|
->executeOne();
|
|
|
|
if (!$revision) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_subclass_of($this->strategyClass, 'DifferentialLandingStrategy')) {
|
|
|
|
$this->pushStrategy = newv($this->strategyClass, array());
|
|
|
|
} else {
|
|
|
|
throw new Exception(
|
|
|
|
"Strategy type must be a valid class name and must subclass ".
|
|
|
|
"DifferentialLandingStrategy. ".
|
|
|
|
"'{$this->strategyClass}' is not a subclass of ".
|
|
|
|
"DifferentialLandingStrategy.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isDialogFormPost()) {
|
Land to GitHub + support stuff
Summary:
A usable, Land to GitHub flow.
Still to do:
- Refactor all git/hg stratagies to a sane structure.
- Make the dialogs Workflow + explain why it's disabled.
- Show button and request Link Account if GH is enabled, but user is not linked.
- After refreshing token, user ends up in the settings stage.
Hacked something in LandController to be able to show an arbitrary dialog from a strategy.
It's not very nice, but I want to make some more refactoring to the controller/strategy/ies anyway.
Also made PhabricatorRepository::getRemoteURIObject() public, because it was very useful in getting
the domain and path for the repo.
Test Plan:
Went through these flows:
- load revision in hosted, github-backed, non-github backed repos to see button as needed.
- hit land with weak token - sent to refresh it with the extra scope.
- Land to repo I'm not allowed - got proper error message.
- Successfully landed; Failed to apply patch.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7555
2013-11-14 02:25:14 +01:00
|
|
|
$response = null;
|
|
|
|
$text = '';
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
try {
|
Land to GitHub + support stuff
Summary:
A usable, Land to GitHub flow.
Still to do:
- Refactor all git/hg stratagies to a sane structure.
- Make the dialogs Workflow + explain why it's disabled.
- Show button and request Link Account if GH is enabled, but user is not linked.
- After refreshing token, user ends up in the settings stage.
Hacked something in LandController to be able to show an arbitrary dialog from a strategy.
It's not very nice, but I want to make some more refactoring to the controller/strategy/ies anyway.
Also made PhabricatorRepository::getRemoteURIObject() public, because it was very useful in getting
the domain and path for the repo.
Test Plan:
Went through these flows:
- load revision in hosted, github-backed, non-github backed repos to see button as needed.
- hit land with weak token - sent to refresh it with the extra scope.
- Land to repo I'm not allowed - got proper error message.
- Successfully landed; Failed to apply patch.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7555
2013-11-14 02:25:14 +01:00
|
|
|
$response = $this->attemptLand($revision, $request);
|
2014-06-09 20:36:49 +02:00
|
|
|
$title = pht('Success!');
|
|
|
|
$text = pht('Revision was successfully landed.');
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
} catch (Exception $ex) {
|
2014-06-09 20:36:49 +02:00
|
|
|
$title = pht('Failed to land revision');
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
if ($ex instanceof PhutilProxyException) {
|
|
|
|
$text = hsprintf(
|
|
|
|
'%s:<br><pre>%s</pre>',
|
|
|
|
$ex->getMessage(),
|
|
|
|
$ex->getPreviousException()->getMessage());
|
|
|
|
} else {
|
2013-11-11 18:23:23 +01:00
|
|
|
$text = phutil_tag('pre', array(), $ex->getMessage());
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
}
|
|
|
|
$text = id(new AphrontErrorView())
|
|
|
|
->appendChild($text);
|
|
|
|
}
|
|
|
|
|
Land to GitHub + support stuff
Summary:
A usable, Land to GitHub flow.
Still to do:
- Refactor all git/hg stratagies to a sane structure.
- Make the dialogs Workflow + explain why it's disabled.
- Show button and request Link Account if GH is enabled, but user is not linked.
- After refreshing token, user ends up in the settings stage.
Hacked something in LandController to be able to show an arbitrary dialog from a strategy.
It's not very nice, but I want to make some more refactoring to the controller/strategy/ies anyway.
Also made PhabricatorRepository::getRemoteURIObject() public, because it was very useful in getting
the domain and path for the repo.
Test Plan:
Went through these flows:
- load revision in hosted, github-backed, non-github backed repos to see button as needed.
- hit land with weak token - sent to refresh it with the extra scope.
- Land to repo I'm not allowed - got proper error message.
- Successfully landed; Failed to apply patch.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7555
2013-11-14 02:25:14 +01:00
|
|
|
if ($response instanceof AphrontDialogView) {
|
|
|
|
$dialog = $response;
|
|
|
|
} else {
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setTitle($title)
|
|
|
|
->appendChild(phutil_tag('p', array(), $text))
|
|
|
|
->addCancelButton('/D'.$revision_id, pht('Done'));
|
|
|
|
}
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
2014-01-30 18:07:50 +01:00
|
|
|
$is_disabled = $this->pushStrategy->isActionDisabled(
|
|
|
|
$viewer,
|
|
|
|
$revision,
|
|
|
|
$revision->getRepository());
|
|
|
|
if ($is_disabled) {
|
|
|
|
if (is_string($is_disabled)) {
|
|
|
|
$explain = $is_disabled;
|
|
|
|
} else {
|
2014-06-09 20:36:49 +02:00
|
|
|
$explain = pht('This action is not currently enabled.');
|
2014-01-30 18:07:50 +01:00
|
|
|
}
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setTitle(pht("Can't land revision"))
|
|
|
|
->appendChild($explain)
|
|
|
|
->addCancelButton('/D'.$revision_id);
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
$prompt = hsprintf('%s<br><br>%s',
|
|
|
|
pht(
|
|
|
|
'This will squash and rebase revision %s, and push it to '.
|
2013-11-08 20:37:57 +01:00
|
|
|
'the default / master branch.',
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
$revision_id),
|
|
|
|
pht('It is an experimental feature and may not work.'));
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($viewer)
|
2014-06-09 20:36:49 +02:00
|
|
|
->setTitle(pht('Land Revision %s?', $revision_id))
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
->appendChild($prompt)
|
|
|
|
->setSubmitURI($request->getRequestURI())
|
|
|
|
->addSubmitButton(pht('Land it!'))
|
|
|
|
->addCancelButton('/D'.$revision_id);
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function attemptLand($revision, $request) {
|
|
|
|
$status = $revision->getStatus();
|
|
|
|
if ($status != ArcanistDifferentialRevisionStatus::ACCEPTED) {
|
2014-06-09 20:36:49 +02:00
|
|
|
throw new Exception('Only Accepted revisions can be landed.');
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$repository = $revision->getRepository();
|
|
|
|
|
|
|
|
if ($repository === null) {
|
2014-06-09 20:36:49 +02:00
|
|
|
throw new Exception('revision is not attached to a repository.');
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$can_push = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$request->getUser(),
|
|
|
|
$repository,
|
2014-07-25 00:20:39 +02:00
|
|
|
DiffusionPushCapability::CAPABILITY);
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
|
|
|
|
if (!$can_push) {
|
|
|
|
throw new Exception(
|
|
|
|
pht('You do not have permission to push to this repository.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$lock = $this->lockRepository($repository);
|
|
|
|
|
|
|
|
try {
|
Land to GitHub + support stuff
Summary:
A usable, Land to GitHub flow.
Still to do:
- Refactor all git/hg stratagies to a sane structure.
- Make the dialogs Workflow + explain why it's disabled.
- Show button and request Link Account if GH is enabled, but user is not linked.
- After refreshing token, user ends up in the settings stage.
Hacked something in LandController to be able to show an arbitrary dialog from a strategy.
It's not very nice, but I want to make some more refactoring to the controller/strategy/ies anyway.
Also made PhabricatorRepository::getRemoteURIObject() public, because it was very useful in getting
the domain and path for the repo.
Test Plan:
Went through these flows:
- load revision in hosted, github-backed, non-github backed repos to see button as needed.
- hit land with weak token - sent to refresh it with the extra scope.
- Land to repo I'm not allowed - got proper error message.
- Successfully landed; Failed to apply patch.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7555
2013-11-14 02:25:14 +01:00
|
|
|
$response = $this->pushStrategy->processLandRequest(
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
$request,
|
|
|
|
$revision,
|
|
|
|
$repository);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$lock->unlock();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
$lock->unlock();
|
2014-06-22 21:30:42 +02:00
|
|
|
|
|
|
|
$looksoon = new ConduitCall(
|
|
|
|
'diffusion.looksoon',
|
|
|
|
array(
|
|
|
|
'callsigns' => array($repository->getCallsign())
|
|
|
|
));
|
|
|
|
$looksoon->setUser($request->getUser());
|
|
|
|
$looksoon->execute();
|
|
|
|
|
Land to GitHub + support stuff
Summary:
A usable, Land to GitHub flow.
Still to do:
- Refactor all git/hg stratagies to a sane structure.
- Make the dialogs Workflow + explain why it's disabled.
- Show button and request Link Account if GH is enabled, but user is not linked.
- After refreshing token, user ends up in the settings stage.
Hacked something in LandController to be able to show an arbitrary dialog from a strategy.
It's not very nice, but I want to make some more refactoring to the controller/strategy/ies anyway.
Also made PhabricatorRepository::getRemoteURIObject() public, because it was very useful in getting
the domain and path for the repo.
Test Plan:
Went through these flows:
- load revision in hosted, github-backed, non-github backed repos to see button as needed.
- hit land with weak token - sent to refresh it with the extra scope.
- Land to repo I'm not allowed - got proper error message.
- Successfully landed; Failed to apply patch.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7555
2013-11-14 02:25:14 +01:00
|
|
|
return $response;
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function lockRepository($repository) {
|
|
|
|
$lock_name = __CLASS__.':'.($repository->getCallsign());
|
|
|
|
$lock = PhabricatorGlobalLock::newLock($lock_name);
|
|
|
|
$lock->lock();
|
|
|
|
return $lock;
|
|
|
|
}
|
2014-07-25 00:20:39 +02:00
|
|
|
|
Land Revision button for hosted git repos
Summary:
ref T182.
Simple approach of clone, patch, push. While waiting for drydock, implement a hackish mutex
setup for the workspace, which should work ok as long as there's only one committer who is
carefull about theses things.
Less obvious note: This is taking the both author and commiter's 'primary email' for the commit -
which might rub some people wrong.
Test Plan:
With a hosted repo, created some diffs and landed them.
Also clicked button for some error cases, got the right error message.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: hach-que, Korvin, epriestley, aran
Maniphest Tasks: T182
Differential Revision: https://secure.phabricator.com/D7486
2013-11-05 22:00:12 +01:00
|
|
|
}
|