22
33namespace AppBundle \Controller ;
44
5- use AppBundle \Event \GitHubEvent ;
6- use AppBundle \Exception \GitHubException ;
75use Sensio \Bundle \FrameworkExtraBundle \Configuration \Method ;
86use Sensio \Bundle \FrameworkExtraBundle \Configuration \Route ;
97use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
@@ -18,42 +16,8 @@ class WebhookController extends Controller
1816 */
1917 public function githubAction (Request $ request )
2018 {
21- $ data = json_decode ($ request ->getContent (), true );
22- if (null === $ data ) {
23- throw new GitHubException ('Invalid JSON body! ' );
24- }
25-
26- $ repository = isset ($ data ['repository ' ]['full_name ' ]) ? $ data ['repository ' ]['full_name ' ] : null ;
27- if (empty ($ repository )) {
28- throw new GitHubException ('No repository name! ' );
29- }
30-
31- $ listener = $ this ->get ('app.github.listener_factory ' )->createFromRepository ($ repository );
32-
33- $ dispatcher = $ this ->get ('event_dispatcher ' );
34- $ dispatcher ->addSubscriber ($ listener );
35-
36- $ event = new GitHubEvent ($ data );
37- $ eventName = $ request ->headers ->get ('X-Github-Event ' );
38-
39- try {
40- $ dispatcher ->dispatch ('github. ' .$ eventName , $ event );
41- } catch (\Exception $ e ) {
42- throw new GitHubException (sprintf ('Failed dispatching "%s" event for "%s" repository. ' , $ eventName , $ repository ), 0 , $ e );
43- }
44-
45- $ responseData = $ event ->getResponseData ();
46-
47- if (empty ($ responseData )) {
48- $ responseData ['unsupported_event ' ] = $ eventName ;
49- }
19+ $ responseData = $ this ->get ('app.github.request_handler ' )->handle ($ request );
5020
5121 return new JsonResponse ($ responseData );
52-
53- // 1 read in what event they have
54- // 2 perform some action
55- // 3 return JSON
56-
57- // log something to the database?
5822 }
5923}
0 commit comments