Skip to content

Commit 2a3fabd

Browse files
committed
Build only last commit for Gitlab. Issue #259.
1 parent 19a3679 commit 2a3fabd

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

src/Controller/WebhookController.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -842,24 +842,25 @@ public function gitlab($projectId)
842842

843843
$results = [];
844844
$status = 'failed';
845-
foreach ($payload['commits'] as $commit) {
846-
try {
847-
$branch = str_replace('refs/heads/', '', $payload['ref']);
848-
$committer = $commit['author']['email'];
849-
$results[$commit['id']] = $this->createBuild(
850-
Build::SOURCE_WEBHOOK_PUSH,
851-
$project,
852-
$commit['id'],
853-
$branch,
854-
null,
855-
$committer,
856-
$commit['message']
857-
);
858-
$status = 'ok';
859-
} catch (Exception $ex) {
860-
$results[$commit['id']] = ['status' => 'failed', 'error' => $ex->getMessage()];
861-
}
845+
846+
$commit = end($payload['commits']);
847+
try {
848+
$branch = str_replace('refs/heads/', '', $payload['ref']);
849+
$committer = $commit['author']['email'];
850+
$results[$commit['id']] = $this->createBuild(
851+
Build::SOURCE_WEBHOOK_PUSH,
852+
$project,
853+
$commit['id'],
854+
$branch,
855+
null,
856+
$committer,
857+
$commit['message']
858+
);
859+
$status = 'ok';
860+
} catch (Exception $ex) {
861+
$results[$commit['id']] = ['status' => 'failed', 'error' => $ex->getMessage()];
862862
}
863+
863864
return ['status' => $status, 'commits' => $results];
864865
}
865866

0 commit comments

Comments
 (0)