diff --git a/docs/en/sources/git.md b/docs/en/sources/git.md index 25be4287..604ae497 100644 --- a/docs/en/sources/git.md +++ b/docs/en/sources/git.md @@ -17,6 +17,13 @@ Installation #!/bin/sh 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/" trigger_hook() { diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index afa43337..542241fc 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -722,7 +722,7 @@ class WebhookController extends Controller /** * Fetch a project and check its type. * - * @param int $projectId + * @param int|string $projectId id or title * @param array|string $expectedType * * @return Project @@ -731,12 +731,23 @@ class WebhookController extends Controller */ protected function fetchProject($projectId, $expectedType) { - $project = $this->projectStore->getById($projectId); - if (empty($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) ? !in_array($project->getType(), $expectedType) : $project->getType() !== $expectedType