diff --git a/PHPCI/Model/Build/GithubBuild.php b/PHPCI/Model/Build/GithubBuild.php index f358355a..58d728ac 100644 --- a/PHPCI/Model/Build/GithubBuild.php +++ b/PHPCI/Model/Build/GithubBuild.php @@ -9,6 +9,7 @@ namespace PHPCI\Model\Build; +use PHPCI\Builder; use PHPCI\Model\Build\RemoteGitBuild; /** @@ -115,4 +116,29 @@ class GithubBuild extends RemoteGitBuild return $link; } + + protected function postCloneSetup(Builder $builder, $cloneTo) + { + $buildType = $this->getExtra('build_type'); + + $success = true; + + try { + if (!empty($buildType) && $buildType == 'pull_request') { + $remoteUrl = $this->getExtra('remote_url'); + $remoteBranch = $this->getExtra('remote_branch'); + + $cmd = 'cd "%s" && git checkout -b phpci/' . $this->getId() . ' %s && git pull %s %s'; + $success = $builder->executeCommand($cmd, $cloneTo, $this->getBranch(), $remoteUrl, $remoteBranch); + } + } catch (\Exception $ex) { + $success = false; + } + + if ($success) { + $success = parent::postCloneSetup($builder, $cloneTo); + } + + return $success; + } } diff --git a/PHPCI/Model/Build/RemoteGitBuild.php b/PHPCI/Model/Build/RemoteGitBuild.php index 9c7c6a26..055d75d8 100644 --- a/PHPCI/Model/Build/RemoteGitBuild.php +++ b/PHPCI/Model/Build/RemoteGitBuild.php @@ -65,12 +65,8 @@ class RemoteGitBuild extends Build $cmd .= ' -b %s %s "%s"'; $success = $builder->executeCommand($cmd, $this->getBranch(), $this->getCloneUrl(), $cloneTo); - if (!empty($commit) && $commit != 'Manual') { - $cmd = 'cd "%s" && git checkout %s'; - if (IS_WIN) { - $cmd = 'cd /d "%s" && git checkout %s'; - } - $builder->executeCommand($cmd, $cloneTo, $this->getCommitId()); + if ($success) { + $success = $this->postCloneSetup($builder, $cloneTo); } return $success; @@ -104,15 +100,8 @@ class RemoteGitBuild extends Build $success = $builder->executeCommand($cmd, $this->getBranch(), $this->getCloneUrl(), $cloneTo); - // Checkout a specific commit if we need to: - $commit = $this->getCommitId(); - - if (!empty($commit) && $commit != 'Manual') { - $cmd = 'cd "%s" && git checkout %s'; - if (IS_WIN) { - $cmd = 'cd /d "%s" && git checkout %s'; - } - $builder->executeCommand($cmd, $cloneTo, $this->getCommitId()); + if ($success) { + $success = $this->postCloneSetup($builder, $cloneTo); } // Remove the key file and git wrapper: @@ -122,6 +111,24 @@ class RemoteGitBuild extends Build return $success; } + protected function postCloneSetup(Builder $builder, $cloneTo) + { + $success = true; + $commit = $this->getCommitId(); + + if (!empty($commit) && $commit != 'Manual') { + $cmd = 'cd "%s" && git checkout %s'; + + if (IS_WIN) { + $cmd = 'cd /d "%s" && git checkout %s'; + } + + $success = $builder->executeCommand($cmd, $cloneTo, $this->getCommitId()); + } + + return $success; + } + /** * Create an SSH key file on disk for this build. * @param $cloneTo