public function handlePush()
{
// We only care about "Tag Push Hook" & "Push Hook" events
if (strpos($this->request->header('X-Gitlab-Event'), 'Push Hook') === false) {
return false;
}
$payload = $this->request->json();
// Sort the commits by the timestamp descending order and then get the first one
$head = collect($payload->get('commits'))->sortByDesc(function ($commit) {
return strtotime($commit['timestamp']);
})->first();
$branch = preg_replace('#refs/(tags|heads)/#', '', $payload->get('ref'));
return ['reason' => trim($head['message']), 'branch' => $branch, 'source' => 'Gitlab', 'build_url' => $head['url'], 'commit' => $head['id'], 'committer' => $head['author']['name'], 'committer_email' => $head['author']['email']];
}