5 * Send out webhook callbacks when something happens
10 * A repository has been created
12 public function create(Repository $repo)
14 $this->send('create', $repo);
18 * A repository has been modified
20 public function edit(Repository $repo)
22 $this->send('edit', $repo);
26 * A repository has been deleted
28 public function delete(Repository $repo)
30 $this->send('delete', $repo);
34 * Call webhook URLs with our payload
36 protected function send($event, Repository $repo)
38 if (count($GLOBALS['phorkie']['cfg']['webhooks']) == 0) {
42 /* slightly inspired by
43 https://help.github.com/articles/post-receive-hooks */
44 $payload = (object) array(
47 'name' => $_SESSION['name'],
48 'email' => $_SESSION['email']
50 'repository' => array(
51 'name' => $repo->getTitle(),
52 'url' => $repo->getLink('display', null, true),
53 'description' => $repo->getDescription(),
54 'owner' => $repo->getOwner()
57 foreach ($GLOBALS['phorkie']['cfg']['webhooks'] as $url) {
58 $req = new \HTTP_Request2($url);
59 $req->setMethod(\HTTP_Request2::METHOD_POST)
60 ->setHeader('Content-Type: application/vnd.phorkie.webhook+json')
61 ->setBody(json_encode($payload));
63 $response = $req->send();
64 //FIXME log response codes != 200
65 } catch (HTTP_Request2_Exception $e) {
66 //FIXME log exceptions