From afa504b9554dfd583b3be66ba0ded51b1bcc8f88 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Mon, 3 Dec 2018 16:42:21 +0100 Subject: [PATCH] Build interface for BaseHandler Add method to determine if process runs in a CI/CD context --- BaseHandler.php | 34 +++++++++++++++------------------- BaseHandlerInterface.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/BaseHandler.php b/BaseHandler.php index 2ade1b5..3cd0de2 100644 --- a/BaseHandler.php +++ b/BaseHandler.php @@ -10,7 +10,7 @@ use Composer\IO\IOInterface; * * @package LakeDrops\Component\Composer */ -abstract class BaseHandler { +abstract class BaseHandler implements BaseHandlerInterface { /** * The composer object of this session. @@ -47,12 +47,9 @@ abstract class BaseHandler { } /** - * Look up the Drupal core package object. - * - * @return \Composer\Package\PackageInterface - * The Drupal core package. + * {@inheritdoc} */ - protected function getDrupalCorePackage() { + public function getDrupalCorePackage() { if (!isset($this->drupalCorePackage)) { $this->drupalCorePackage = $this->getPackage('drupal/core'); } @@ -60,25 +57,24 @@ abstract class BaseHandler { } /** - * Retrieve a package from the current composer process. - * - * @param string $name - * Name of the package to get from the current composer installation. - * - * @return \Composer\Package\PackageInterface - * The package. + * {@inheritdoc} */ - protected function getPackage($name) { + public function getPackage($name) { return $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*'); } /** - * Wrapper for git command in the root directory. - * - * @param string $command - * Git command name, arguments and/or options. + * {@inheritdoc} + */ + public function isCiContext() { + $ci_project_dir = getenv('CI_PROJECT_DIR'); + return !empty($ci_project_dir ); + } + + /** + * {@inheritdoc} */ - protected function git($command) { + public function git($command) { passthru(escapeshellcmd('git -c "user.email=composer@lakedrops.com" ' . $command)); } diff --git a/BaseHandlerInterface.php b/BaseHandlerInterface.php index 135a499..8ea968a 100644 --- a/BaseHandlerInterface.php +++ b/BaseHandlerInterface.php @@ -9,4 +9,38 @@ namespace LakeDrops\Component\Composer; */ interface BaseHandlerInterface { + /** + * Look up the Drupal core package object. + * + * @return \Composer\Package\PackageInterface + * The Drupal core package. + */ + public function getDrupalCorePackage(); + + /** + * Retrieve a package from the current composer process. + * + * @param string $name + * Name of the package to get from the current composer installation. + * + * @return \Composer\Package\PackageInterface + * The package. + */ + public function getPackage($name); + + /** + * Determine if the current process runs in a CI/CD context. + * + * @return bool + */ + public function isCiContext(); + + /** + * Wrapper for git command in the root directory. + * + * @param string $command + * Git command name, arguments and/or options. + */ + public function git($command); + } -- GitLab