5 * Send out webhook callbacks when something happens
7 class Notificator_Webhook
11 public function __construct($config)
13 $this->config = $config;
17 * Call webhook URLs with our payload
19 public function send($event, Repository $repo)
21 if (count($this->config) == 0) {
25 /* slightly inspired by
26 https://help.github.com/articles/post-receive-hooks */
27 $payload = (object) array(
30 'name' => $_SESSION['name'],
31 'email' => $_SESSION['email']
33 'repository' => array(
34 'name' => $repo->getTitle(),
35 'url' => $repo->getLink('display', null, true),
36 'description' => $repo->getDescription(),
37 'owner' => $repo->getOwner()
40 foreach ($this->config as $url) {
41 $req = new \HTTP_Request2($url);
42 $req->setMethod(\HTTP_Request2::METHOD_POST)
43 ->setHeader('Content-Type: application/vnd.phorkie.webhook+json')
44 ->setBody(json_encode($payload));
46 $response = $req->send();
47 //FIXME log response codes != 200
48 } catch (HTTP_Request2_Exception $e) {
49 //FIXME log exceptions