X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/934246267dc4089dc0952bbe8412f32fd7346739..f47ddf0758f120dfb26f03fb36be5cd897a10f23:/src/phorkie/Repository/LinkbackReceiver.php diff --git a/src/phorkie/Repository/LinkbackReceiver.php b/src/phorkie/Repository/LinkbackReceiver.php new file mode 100644 index 0000000..bce7643 --- /dev/null +++ b/src/phorkie/Repository/LinkbackReceiver.php @@ -0,0 +1,88 @@ +repo = $repo; + } + + public function storeLinkback( + $target, $source, $sourceBody, \HTTP_Request2_Response $res + ) { + //FIXME: deleted + //FIXME: updated + //FIXME: cleanuptask + + $hp = new HtmlParser(); + $ok = $hp->extractGitUrls($source, $sourceBody); + if ($ok === false) { + //failed to extract git URL from linkback source + //FIXME: send exception + //$hp->error + return; + } + + $ci = $this->repo->getConnectionInfo(); + $forks = $ci->getForks(); + + $remoteCloneUrl = $remoteTitle = null; + $arRemoteCloneUrls = array(); + $arGitUrls = $hp->getGitUrls(); + foreach ($arGitUrls as $remoteTitle => $arUrls) { + foreach ($arUrls as $remoteCloneUrl) { + $arRemoteCloneUrls[$remoteCloneUrl] = $remoteTitle; + } + } + + $remoteid = 'fork-' . uniqid(); + //check if we already know this remote + foreach ($forks as $remote) { + if (isset($arRemoteCloneUrls[$remote->getCloneUrl()]) + || $source == $remote->getWebURL(true) + ) { + $remoteid = $remote->getName(); + break; + } + } + + if ($this->isLocalWebUrl($source)) { + //convert both web and clone url to local urls + } + + $vc = $this->repo->getVc(); + $vc->getCommand('config') + ->addArgument('remote.' . $remoteid . '.homepage') + ->addArgument($source) + ->execute(); + if ($remoteTitle !== null) { + $vc->getCommand('config') + ->addArgument('remote.' . $remoteid . '.title') + ->addArgument($remoteTitle) + ->execute(); + } + if ($remoteCloneUrl !== null) { + $vc->getCommand('config') + ->addArgument('remote.' . $remoteid . '.url') + ->addArgument($remoteCloneUrl) + ->execute(); + } + } + + protected function isLocalWebUrl($url) + { + $base = Tools::fullUrl(); + if (substr($url, 0, strlen($base)) != $base) { + //base does not match + return false; + } + + $remainder = substr($url, strlen($base)); + //FIXME: check if it exists + } +} +?>