Skip to content

Commit

Permalink
Fix bug in API request parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nekudo committed Jul 17, 2021
1 parent 450ec80 commit 9f20499
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/ShinyDeploy/Core/RequestParser/Bitbucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ public function parseRequest(): bool
}

// fetch branch name
if (!empty($requestParams['push']['changes'][0]['new']['name'])) {
$branchParts = explode('/', $requestParams['push']['changes'][0]['new']['name']);
$this->parameters['branch'] = array_pop($branchParts);
if (empty($requestParams['push']['changes'][0]['new']['name'])) {
return false;
}
$branchParts = explode('/', $requestParams['push']['changes'][0]['new']['name']);
$this->parameters['branch'] = array_pop($branchParts);

// fetch revision hash
if (!empty($requestParams['push']['changes'][0]['new']['target']['hash'])) {
$this->parameters['revision'] = $requestParams['push']['changes'][0]['new']['target']['hash'];
if (empty($requestParams['push']['changes'][0]['new']['target']['hash'])) {
return false;
}
$this->parameters['revision'] = $requestParams['push']['changes'][0]['new']['target']['hash'];

return true;
}
Expand Down
17 changes: 12 additions & 5 deletions src/ShinyDeploy/Core/RequestParser/Gitea.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ public function parseRequest(): bool
if (empty($requestParams)) {
return false;
}
if (!empty($payload['ref'])) {
$branchParts = explode('/', $payload['ref']);
$this->parameters['branch'] = array_pop($branchParts);

// fetch branch name
if (empty($requestParams['ref'])) {
return false;
}
if (!empty($payload['after'])) {
$this->parameters['revision'] = $payload['after'];
$branchParts = explode('/', $requestParams['ref']);
$this->parameters['branch'] = array_pop($branchParts);

// fetch revision hash
if (empty($requestParams['after'])) {
return false;
}
$this->parameters['revision'] = $requestParams['after'];

return true;
}

Expand Down
20 changes: 15 additions & 5 deletions src/ShinyDeploy/Core/RequestParser/Github.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ public function parseRequest(): bool
return false;
}
$payload = json_decode($_REQUEST['payload'], true);
if (!empty($payload['ref'])) {
$branchParts = explode('/', $payload['ref']);
$this->parameters['branch'] = array_pop($branchParts);
if (empty($payload)) {
return false;
}
if (!empty($payload['after'])) {
$this->parameters['revision'] = $payload['after'];

// fetch branch name
if (empty($payload['ref'])) {
return false;
}
$branchParts = explode('/', $payload['ref']);
$this->parameters['branch'] = array_pop($branchParts);

// fetch revision hash
if (empty($payload['after'])) {
return false;
}
$this->parameters['revision'] = $payload['after'];

return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/ShinyDeploy/Core/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function handleRequest(): void
{
try {
$this->parseRequest();
$this->logger->debug('API request parsed.', $this->requestParams);
$this->validateRequest();
$this->executeRequest();
} catch (ShinyDeployException $e) {
Expand Down

0 comments on commit 9f20499

Please sign in to comment.