Allow specify project title in webhook request
This commit is contained in:
parent
08e3b564b9
commit
eca63d81e2
|
@ -17,6 +17,13 @@ Installation
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
PROJECT_ID=1
|
PROJECT_ID=1
|
||||||
|
|
||||||
|
# You can use the project title instead of the id:
|
||||||
|
# PROJECT_ID=my_project_title
|
||||||
|
|
||||||
|
# If the names of the repository and the project match:
|
||||||
|
# PROJECT_ID=`basename \`pwd\` | sed 's#\.git$##'`
|
||||||
|
|
||||||
APP_URL="http://my.server.com/php-censor/"
|
APP_URL="http://my.server.com/php-censor/"
|
||||||
|
|
||||||
trigger_hook() {
|
trigger_hook() {
|
||||||
|
|
|
@ -722,7 +722,7 @@ class WebhookController extends Controller
|
||||||
/**
|
/**
|
||||||
* Fetch a project and check its type.
|
* Fetch a project and check its type.
|
||||||
*
|
*
|
||||||
* @param int $projectId
|
* @param int|string $projectId id or title
|
||||||
* @param array|string $expectedType
|
* @param array|string $expectedType
|
||||||
*
|
*
|
||||||
* @return Project
|
* @return Project
|
||||||
|
@ -731,12 +731,23 @@ class WebhookController extends Controller
|
||||||
*/
|
*/
|
||||||
protected function fetchProject($projectId, $expectedType)
|
protected function fetchProject($projectId, $expectedType)
|
||||||
{
|
{
|
||||||
$project = $this->projectStore->getById($projectId);
|
|
||||||
|
|
||||||
if (empty($projectId)) {
|
if (empty($projectId)) {
|
||||||
throw new Exception('Project does not exist: ' . $projectId);
|
throw new Exception('Project does not exist: ' . $projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_numeric($projectId)) {
|
||||||
|
$project = $this->projectStore->getById($projectId);
|
||||||
|
} else {
|
||||||
|
$projects = $this->projectStore->getByTitle($projectId, 2);
|
||||||
|
if ($projects['count'] < 1) {
|
||||||
|
throw new Exception('Project does not found: ' . $projectId);
|
||||||
|
}
|
||||||
|
if ($projects['count'] > 1) {
|
||||||
|
throw new Exception('Project id is ambiguous: ' . $projectId);
|
||||||
|
}
|
||||||
|
$project = reset($projects['items']);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_array($expectedType)
|
if (is_array($expectedType)
|
||||||
? !in_array($project->getType(), $expectedType)
|
? !in_array($project->getType(), $expectedType)
|
||||||
: $project->getType() !== $expectedType
|
: $project->getType() !== $expectedType
|
||||||
|
|
Loading…
Reference in a new issue