mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Actually push to mirrors
Summary: Fixes T4038. Push repositories to mirrors. Test Plan: Created a functional mirror of a local: https://github.com/epriestley/poems Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4038 Differential Revision: https://secure.phabricator.com/D7633
This commit is contained in:
parent
4b91c4f7ae
commit
d09dd23bd7
3 changed files with 51 additions and 17 deletions
|
@ -7,21 +7,6 @@
|
||||||
$root = dirname(dirname(dirname(__FILE__)));
|
$root = dirname(dirname(dirname(__FILE__)));
|
||||||
require_once $root.'/scripts/__init_script__.php';
|
require_once $root.'/scripts/__init_script__.php';
|
||||||
|
|
||||||
$target_name = getenv('PHABRICATOR_SSH_TARGET');
|
|
||||||
if (!$target_name) {
|
|
||||||
throw new Exception(pht("No 'PHABRICATOR_SSH_TARGET' in environment!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
$viewer = PhabricatorUser::getOmnipotentUser();
|
|
||||||
|
|
||||||
$repository = id(new PhabricatorRepositoryQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withCallsigns(array($target_name))
|
|
||||||
->executeOne();
|
|
||||||
if (!$repository) {
|
|
||||||
throw new Exception(pht('No repository with callsign "%s"!', $target_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
$pattern = array();
|
$pattern = array();
|
||||||
$arguments = array();
|
$arguments = array();
|
||||||
|
|
||||||
|
@ -30,8 +15,9 @@ $pattern[] = 'ssh';
|
||||||
$pattern[] = '-o';
|
$pattern[] = '-o';
|
||||||
$pattern[] = 'StrictHostKeyChecking=no';
|
$pattern[] = 'StrictHostKeyChecking=no';
|
||||||
|
|
||||||
$credential_phid = $repository->getCredentialPHID();
|
$credential_phid = getenv('PHABRICATOR_CREDENTIAL');
|
||||||
if ($credential_phid) {
|
if ($credential_phid) {
|
||||||
|
$viewer = PhabricatorUser::getOmnipotentUser();
|
||||||
$key = PassphraseSSHKey::loadFromPHID($credential_phid, $viewer);
|
$key = PassphraseSSHKey::loadFromPHID($credential_phid, $viewer);
|
||||||
|
|
||||||
$pattern[] = '-l %P';
|
$pattern[] = '-l %P';
|
||||||
|
|
|
@ -252,6 +252,15 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
|
|
||||||
$this->checkIfRepositoryIsFullyImported($repository);
|
$this->checkIfRepositoryIsFullyImported($repository);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->pushToMirrors($repository);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
// TODO: We should report these into the UI properly, but for
|
||||||
|
// now just complain. These errors are much less severe than
|
||||||
|
// pull errors.
|
||||||
|
phlog($ex);
|
||||||
|
}
|
||||||
|
|
||||||
if ($refs !== null) {
|
if ($refs !== null) {
|
||||||
return (bool)count($refs);
|
return (bool)count($refs);
|
||||||
} else {
|
} else {
|
||||||
|
@ -802,4 +811,43 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function pushToMirrors(PhabricatorRepository $repository) {
|
||||||
|
if (!$repository->canMirror()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mirrors = id(new PhabricatorRepositoryMirrorQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->withRepositoryPHIDs(array($repository->getPHID()))
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
// TODO: This is a little bit janky, but we don't have first-class
|
||||||
|
// infrastructure for running remote commands against an arbitrary remote
|
||||||
|
// right now. Just make an emphemeral copy of the repository and muck with
|
||||||
|
// it a little bit. In the medium term, we should pull this command stuff
|
||||||
|
// out and use it here and for "Land to ...".
|
||||||
|
|
||||||
|
$proxy = clone $repository;
|
||||||
|
$proxy->makeEphemeral();
|
||||||
|
|
||||||
|
$proxy->setDetail('hosting-enabled', false);
|
||||||
|
foreach ($mirrors as $mirror) {
|
||||||
|
$proxy->setDetail('remote-uri', $mirror->getRemoteURI());
|
||||||
|
$proxy->setCredentialPHID($mirror->getCredentialPHID());
|
||||||
|
|
||||||
|
$this->log(pht('Pushing to remote "%s"...', $mirror->getRemoteURI()));
|
||||||
|
|
||||||
|
if (!$proxy->isGit()) {
|
||||||
|
throw new Exception('Unsupported VCS!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$future = $proxy->getRemoteCommandFuture(
|
||||||
|
'push --verbose --mirror -- %s',
|
||||||
|
$proxy->getRemoteURI());
|
||||||
|
|
||||||
|
$future
|
||||||
|
->setCWD($proxy->getLocalPath())
|
||||||
|
->resolvex();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,7 +337,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
||||||
if ($this->shouldUseSSH()) {
|
if ($this->shouldUseSSH()) {
|
||||||
// NOTE: This is read by `bin/ssh-connect`, and tells it which credentials
|
// NOTE: This is read by `bin/ssh-connect`, and tells it which credentials
|
||||||
// to use.
|
// to use.
|
||||||
$env['PHABRICATOR_SSH_TARGET'] = $this->getCallsign();
|
$env['PHABRICATOR_CREDENTIAL'] = $this->getCredentialPHID();
|
||||||
switch ($this->getVersionControlSystem()) {
|
switch ($this->getVersionControlSystem()) {
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||||
// Force SVN to use `bin/ssh-connect`.
|
// Force SVN to use `bin/ssh-connect`.
|
||||||
|
|
Loading…
Reference in a new issue