Skip to content
Permalink
Browse files

Add support for rebuild on Git webhook (#1346)

Enables for example a maintainer to run a daily build of their project,
whether a change has been made or not. The rebuild parameter is made
fully optional.
  • Loading branch information...
mathysie authored and Dan Cryer committed Jun 18, 2018
1 parent 170bba6 commit 2b89233fe3891a4ddf953d457f8a0bb70550a85b
Showing with 15 additions and 10 deletions.
  1. +15 −10 PHPCI/Controller/WebhookController.php
@@ -178,8 +178,9 @@ public function git($projectId)
$commit = $this->getParam('commit');
$commitMessage = $this->getParam('message');
$committer = $this->getParam('committer');
$rebuild = $this->getParam('rebuild') ?? false;
return $this->createBuild($project, $commit, $branch, $committer, $commitMessage);
return $this->createBuild($project, $commit, $branch, $committer, $commitMessage, $rebuild);
}
/**
@@ -325,7 +326,7 @@ protected function githubPullRequest(Project $project, array $payload)
'remote_url' => $payload['pull_request']['head']['repo'][$remoteUrlKey],
);
$results[$id] = $this->createBuild($project, $id, $branch, $committer, $message, $extra);
$results[$id] = $this->createBuild($project, $id, $branch, $committer, $message, false, $extra);
$status = 'ok';
} catch (Exception $ex) {
$results[$id] = array('status' => 'failed', 'error' => $ex->getMessage());
@@ -411,6 +412,7 @@ public function svn($projectId)
* @param string $branch
* @param string $committer
* @param string $commitMessage
* @param bool $rebuild
* @param array $extra
*
* @return array
@@ -423,16 +425,19 @@ protected function createBuild(
$branch,
$committer,
$commitMessage,
bool $rebuild = false,
array $extra = null
) {
// Check if a build already exists for this commit ID:
$builds = $this->buildStore->getByProjectAndCommit($project->getId(), $commitId);
if ($builds['count']) {
return array(
'status' => 'ignored',
'message' => sprintf('Duplicate of build #%d', $builds['items'][0]->getId())
);
// Check if a build already exists for this commit ID when not rebuilding:
if (!$rebuild) {
$builds = $this->buildStore->getByProjectAndCommit($project->getId(), $commitId);
if ($builds['count']) {
return array(
'status' => 'ignored',
'message' => sprintf('Duplicate of build #%d', $builds['items'][0]->getId())
);
}
}
// If not, create a new build job for it:

0 comments on commit 2b89233

Please sign in to comment.
You can’t perform that action at this time.