aboutsummaryrefslogtreecommitdiff
path: root/src/phorkie/Repository
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2013-11-22 21:32:06 +0100
committerChristian Weiske <cweiske@cweiske.de>2013-11-22 21:32:06 +0100
commitf47ddf0758f120dfb26f03fb36be5cd897a10f23 (patch)
tree9b64102a66eff570eee85c382688a2f1d423beb4 /src/phorkie/Repository
parent934246267dc4089dc0952bbe8412f32fd7346739 (diff)
downloadphorkie-f47ddf0758f120dfb26f03fb36be5cd897a10f23.tar.gz
phorkie-f47ddf0758f120dfb26f03fb36be5cd897a10f23.zip
first work on remote fork notifications with linkback (webmention/pingback)
Diffstat (limited to 'src/phorkie/Repository')
-rw-r--r--src/phorkie/Repository/ConnectionInfo.php20
-rw-r--r--src/phorkie/Repository/LinkbackReceiver.php88
-rw-r--r--src/phorkie/Repository/Remote.php14
3 files changed, 117 insertions, 5 deletions
diff --git a/src/phorkie/Repository/ConnectionInfo.php b/src/phorkie/Repository/ConnectionInfo.php
index 3815856..ce96c3e 100644
--- a/src/phorkie/Repository/ConnectionInfo.php
+++ b/src/phorkie/Repository/ConnectionInfo.php
@@ -18,6 +18,11 @@ class Repository_ConnectionInfo
return $this->getOrigin() !== null;
}
+ public function hasForks()
+ {
+ return count($this->getForks()) > 0;
+ }
+
public function getOrigin()
{
@@ -36,7 +41,18 @@ class Repository_ConnectionInfo
return new Repository_Remote($name, $this->arConfig['remote ' . $name]);
}
+ public function getForks()
+ {
+ $arForks = array();
+ foreach ($this->arConfig as $name => $data) {
+ if (substr($name, 0, 12) != 'remote fork-') {
+ continue;
+ }
+ $arForks[substr($name, 7)] = new Repository_Remote(
+ substr($name, 7), $data
+ );
+ }
+ return $arForks;
+ }
}
-
-
?>
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 @@
+<?php
+namespace phorkie;
+
+class Repository_LinkbackReceiver
+ implements \PEAR2\Services\Linkback\Server\Callback\IStorage
+{
+ protected $repo;
+
+ public function __construct($repo)
+ {
+ $this->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
+ }
+}
+?>
diff --git a/src/phorkie/Repository/Remote.php b/src/phorkie/Repository/Remote.php
index 4f5034c..3bb153f 100644
--- a/src/phorkie/Repository/Remote.php
+++ b/src/phorkie/Repository/Remote.php
@@ -13,6 +13,11 @@ class Repository_Remote
}
+ public function getName()
+ {
+ return $this->name;
+ }
+
public function getTitle()
{
if (isset($this->arConfig['title'])) {
@@ -38,10 +43,13 @@ class Repository_Remote
}
}
- return $this->arConfig['url'];
+ if (isset($this->arConfig['url'])) {
+ return $this->arConfig['url'];
+ }
+ return null;
}
- public function getWebURL()
+ public function getWebURL($full = false)
{
if (isset($this->arConfig['homepage'])) {
return $this->arConfig['homepage'];
@@ -50,7 +58,7 @@ class Repository_Remote
if ($this->isLocal()) {
$local = $this->getLocalRepository();
if ($local !== null) {
- return $local->getLink('display');
+ return $local->getLink('display', null, $full);
}
}