From f47ddf0758f120dfb26f03fb36be5cd897a10f23 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 22 Nov 2013 21:32:06 +0100 Subject: first work on remote fork notifications with linkback (webmention/pingback) --- src/phorkie/Notificator/Webhook.php | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/phorkie/Notificator/Webhook.php (limited to 'src/phorkie/Notificator/Webhook.php') diff --git a/src/phorkie/Notificator/Webhook.php b/src/phorkie/Notificator/Webhook.php new file mode 100644 index 0000000..5737243 --- /dev/null +++ b/src/phorkie/Notificator/Webhook.php @@ -0,0 +1,55 @@ +config = $config; + } + + /** + * Call webhook URLs with our payload + */ + public function send($event, Repository $repo) + { + if (count($this->config) == 0) { + return; + } + + /* slightly inspired by + https://help.github.com/articles/post-receive-hooks */ + $payload = (object) array( + 'event' => $event, + 'author' => array( + 'name' => $_SESSION['name'], + 'email' => $_SESSION['email'] + ), + 'repository' => array( + 'name' => $repo->getTitle(), + 'url' => $repo->getLink('display', null, true), + 'description' => $repo->getDescription(), + 'owner' => $repo->getOwner() + ) + ); + foreach ($this->config as $url) { + $req = new \HTTP_Request2($url); + $req->setMethod(\HTTP_Request2::METHOD_POST) + ->setHeader('Content-Type: application/vnd.phorkie.webhook+json') + ->setBody(json_encode($payload)); + try { + $response = $req->send(); + //FIXME log response codes != 200 + } catch (HTTP_Request2_Exception $e) { + //FIXME log exceptions + } + } + } +} +?> + -- cgit v1.2.3