Skip to content

Commit

Permalink
Merge pull request #40 from bezio/feature/add_onpremise_bitbucket
Browse files Browse the repository at this point in the history
added bitbucket on-premise to the webook-callees
  • Loading branch information
vtsykun authored Dec 28, 2022
2 parents 325e1da + 5599f52 commit 5f6e866
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Packagist/WebBundle/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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\.)?(?P<host>bitbucket\.org)[/:](?P<path>[\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<host>[a-z0-9.-]+)(?::[0-9]+/|[:/])(?P<path>[\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@)?(?P<host>bitbucket\.org)[/:](?P<path>[\w.-]+/[\w.-]+?)(\.git)?/?$}i';
$url = $payload['canon_url'] . $payload['repository']['absolute_url'];
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 5f6e866

Please sign in to comment.