Skip to content

Commit

Permalink
Add support for rebuild on Git webhook (#1346)
Browse files Browse the repository at this point in the history
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 2b89233
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions PHPCI/Controller/WebhookController.php
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 2b89233

Please sign in to comment.