1. Go to this page and download the library: Download swop/github-webhook-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
swop / github-webhook-bundle example snippets
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Swop\Bundle\GitHubWebHookBundle\GitHubWebHookBundle()
];
// ...
}
}
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Swop\GitHubWebHook\Event\GitHubEvent;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Swop\Bundle\GitHubWebHookBundle\Annotation\GitHubWebHook;
class DefaultController extends Controller
{
/**
* @Route("/webhook", name="webhook")
*
* @GitHubWebHook(eventType="push")
* @GitHubWebHook(eventType="pull_request")
*/
public function indexAction(GitHubEvent $gitHubEvent)
{
$payload = $gitHubEvent->getPayload(); // Request payload (array)
$eventType = $gitHubEvent->getType(); // "pull" or "pull_request"
// Do something depending on the payload & the event type...
return ['status' => 'success'];
}
}