diff --git a/src/Packagist/WebBundle/Controller/ApiController.php b/src/Packagist/WebBundle/Controller/ApiController.php index 5314560b..9ae0da34 100644 --- a/src/Packagist/WebBundle/Controller/ApiController.php +++ b/src/Packagist/WebBundle/Controller/ApiController.php @@ -79,7 +79,7 @@ public function updatePackageAction(Request $request) { // parse the payload $payload = json_decode($request->request->get('payload'), true); - if (!$payload && $request->headers->get('Content-Type') === 'application/json') { + if (!$payload && 0 === strpos($request->headers->get('Content-Type'), 'application/json')) { $payload = json_decode($request->getContent(), true); } @@ -110,6 +110,15 @@ public function updatePackageAction(Request $request) } elseif (isset($payload['repository']['links']['html']['href'])) { // bitbucket push event payload $urlRegex = '{^(?:https?://|git://|git@)?(?:api\.)?(?Pbitbucket\.org)[/:](?P[\w.-]+/[\w.-]+?)(\.git)?/?$}i'; $url = $payload['repository']['links']['html']['href']; + } elseif (isset($payload['repository']['links']['clone'][0]['href'])) { // bitbucket on-premise + $urlRegex = '{^(?:ssh://git@|https?://|git://|git@)?(?P[a-z0-9.-]+)(?::[0-9]+/|[:/])(?P[\w.-]+(?:/[\w.-]+?)+)(?:\.git|/)?$}i'; + $url = ''; + foreach ($payload['repository']['links']['clone'] as $id => $data) { + if ($data['name'] == 'ssh') { + $url = $data['href']; + break; + } + } } elseif (isset($payload['canon_url']) && isset($payload['repository']['absolute_url'])) { // bitbucket post hook (deprecated) $urlRegex = '{^(?:https?://|git://|git@)?(?Pbitbucket\.org)[/:](?P[\w.-]+/[\w.-]+?)(\.git)?/?$}i'; $url = $payload['canon_url'] . $payload['repository']['absolute_url']; @@ -155,7 +164,7 @@ public function editPackageAction(Request $request, Package $package) } $payload = json_decode($request->request->get('payload'), true); - if (!$payload && $request->headers->get('Content-Type') === 'application/json') { + if (!$payload && 0 === strpos($request->headers->get('Content-Type'), 'application/json')) { $payload = json_decode($request->getContent(), true); }