From efe482a98a70289e2ce673ea8afec2b62ab17015 Mon Sep 17 00:00:00 2001 From: Lukz Date: Thu, 14 May 2015 12:28:46 -0300 Subject: [PATCH 1/3] Support to Gitlab versions prior to 7.3 If the version of gitlab is prior to 7.3 the paylod doesn't contains infomation about the commit and the commiter, and the build is not open. With this additional the build will be open as a manual build. --- PHPCI/Controller/WebhookController.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index 45a775ad..57ab6b9a 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -290,19 +290,23 @@ class WebhookController extends \b8\Controller $payloadString = file_get_contents("php://input"); $payload = json_decode($payloadString, true); - // build on merge request events - if (isset($payload['object_kind']) && $payload['object_kind'] == 'merge_request') { - $attributes = $payload['object_attributes']; - if ($attributes['state'] == 'opened' || $attributes['state'] == 'reopened') { - $branch = $attributes['source_branch']; - $commit = $attributes['last_commit']; - $committer = $commit['author']['email']; + // build on merge request events + if (isset($payload['object_kind']) && $payload['object_kind'] == 'merge_request') { - return $this->createBuild($project, $commit['id'], $branch, $committer, $commit['message']); - } - } + $attributes = $payload['object_attributes']; - // build on push events + if ($attributes['state'] == 'opened' || $attributes['state'] == 'reopened') { + $branch = $attributes['source_branch']; + $commit = isset($attributes['last_commit']) ? $attributes['last_commit'] : null; + $committer = isset($commit['author']['email']) ? $commit['author']['email'] : null; + $message = isset($commit['message']) ? $commit['message'] : null; + + return $this->createBuild($project, $commit['id'], $branch, $committer, $message); + } + } + + + // build on push events if (isset($payload['commits']) && is_array($payload['commits'])) { // If we have a list of commits, then add them all as builds to be tested: From 4873d7b3b102cdb10fa35094152fa3d18c29c7c8 Mon Sep 17 00:00:00 2001 From: Lukz Date: Thu, 14 May 2015 12:31:54 -0300 Subject: [PATCH 2/3] Support to Gitlab versions prior to 7.3 Changed tabs characters to spaces. --- PHPCI/Controller/WebhookController.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index 57ab6b9a..7ee615d8 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -290,23 +290,23 @@ class WebhookController extends \b8\Controller $payloadString = file_get_contents("php://input"); $payload = json_decode($payloadString, true); - // build on merge request events - if (isset($payload['object_kind']) && $payload['object_kind'] == 'merge_request') { + // build on merge request events + if (isset($payload['object_kind']) && $payload['object_kind'] == 'merge_request') { - $attributes = $payload['object_attributes']; + $attributes = $payload['object_attributes']; - if ($attributes['state'] == 'opened' || $attributes['state'] == 'reopened') { - $branch = $attributes['source_branch']; - $commit = isset($attributes['last_commit']) ? $attributes['last_commit'] : null; - $committer = isset($commit['author']['email']) ? $commit['author']['email'] : null; - $message = isset($commit['message']) ? $commit['message'] : null; + if ($attributes['state'] == 'opened' || $attributes['state'] == 'reopened') { + $branch = $attributes['source_branch']; + $commit = isset($attributes['last_commit']) ? $attributes['last_commit'] : null; + $committer = isset($commit['author']['email']) ? $commit['author']['email'] : null; + $message = isset($commit['message']) ? $commit['message'] : null; - return $this->createBuild($project, $commit['id'], $branch, $committer, $message); - } - } + return $this->createBuild($project, $commit['id'], $branch, $committer, $message); + } + } - // build on push events + // build on push events if (isset($payload['commits']) && is_array($payload['commits'])) { // If we have a list of commits, then add them all as builds to be tested: From 15ee7834c4e88d85fffae41f2d1d69167e884e30 Mon Sep 17 00:00:00 2001 From: Lukz Date: Thu, 14 May 2015 12:38:55 -0300 Subject: [PATCH 3/3] Support to Gitlab versions prior to 7.3 Adjustments in the code format. --- PHPCI/Controller/WebhookController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index 7ee615d8..64c36e8e 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -292,7 +292,6 @@ class WebhookController extends \b8\Controller // build on merge request events if (isset($payload['object_kind']) && $payload['object_kind'] == 'merge_request') { - $attributes = $payload['object_attributes']; if ($attributes['state'] == 'opened' || $attributes['state'] == 'reopened') {