From 0e83599b9f402fa9a7b0a6aea787501257337e5a Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Thu, 20 Apr 2017 20:38:02 +0700 Subject: [PATCH] Refactored push and tag webhooks for Github (Fixes). --- src/PHPCensor/Controller/WebhookController.php | 2 +- src/PHPCensor/Store/BuildStore.php | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index c17564ec..37a27766 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -513,7 +513,7 @@ class WebhookController extends Controller } // Check if a build already exists for this commit ID: - $builds = $this->buildStore->getByProjectAndCommit($project->getId(), $commitId); + $builds = $this->buildStore->getByProjectAndCommit($project->getId(), $commitId, $branch); $ignore_environments = []; if ($builds['count']) { diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 793d9a5f..47485e3f 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -177,16 +177,21 @@ class BuildStore extends Store /** * Return an array of builds for a given project and commit ID. - * @param $projectId - * @param $commitId + * + * @param integer $projectId + * @param string $commitId + * @param string $branch + * * @return array */ - public function getByProjectAndCommit($projectId, $commitId) + public function getByProjectAndCommit($projectId, $commitId, $branch) { - $query = 'SELECT * FROM {{build}} WHERE {{project_id}} = :project_id AND {{commit_id}} = :commit_id'; - $stmt = Database::getConnection('read')->prepareCommon($query); + $query = 'SELECT * FROM {{build}} WHERE {{project_id}} = :project_id AND {{commit_id}} = :commit_id AND {{branch}} = :branch'; + $stmt = Database::getConnection('read')->prepareCommon($query); + $stmt->bindValue(':project_id', $projectId); $stmt->bindValue(':commit_id', $commitId); + $stmt->bindValue(':branch', $branch); if ($stmt->execute()) { $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);