Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/en/sources/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
17 changes: 14 additions & 3 deletions src/PHPCensor/Controller/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ protected function createBuild(
/**
* Fetch a project and check its type.
*
* @param int $projectId
* @param int|string $projectId id or title
* @param array|string $expectedType
*
* @return Project
Expand All @@ -731,12 +731,23 @@ protected function createBuild(
*/
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
Expand Down