예제 #1
1
파일: Api.php 프로젝트: martinsv/bart
 /**
  * @param array $conf Configurations for reaching Gerrit server
  */
 public function __construct()
 {
     /** @var \Bart\Configuration\GerritConfig $config */
     $config = Diesel::create('Bart\\Configuration\\GerritConfig');
     /** @var \Bart\SshWrapper $ssh */
     $ssh = Diesel::create('Bart\\SshWrapper', $config->host(), $config->sshPort());
     $ssh->setCredentials($config->sshUser(), $config->sshKeyFile());
     $this->ssh = $ssh;
     $this->config = $config;
     $this->logger = Log4PHP::getLogger(__CLASS__);
     $this->logger->trace("Configured Gerrit API using ssh {$ssh}");
 }
예제 #2
0
 /**
  * @param Commit $commit current commit against which hook is being run
  */
 public function __construct(Commit $commit)
 {
     $this->logger = Log4PHP::getLogger(get_called_class());
     $this->commit = $commit;
     /** @var \Bart\GitHook\GitHookConfig configs */
     $this->configs = Diesel::create('\\Bart\\GitHook\\GitHookConfig', $this->commit);
 }
예제 #3
0
파일: Job.php 프로젝트: martinsv/bart
 /**
  * Job constructor. Loads metadata about a project.
  * @param Connection $connection
  * @param string $projectPath This parameter specifies the location of the Jenkins Job.
  * For example, if your Job is defined in the following third level project: Base->Build->Example,
  * you must pass in the full path to the project, 'job/Base/job/Build/job/Example'.
  */
 public function __construct(Connection $connection, $projectPath)
 {
     if (!is_string($projectPath)) {
         throw new \InvalidArgumentException('The projectPath must be of type string');
     }
     $this->connection = $connection;
     $this->logger = Log4PHP::getLogger(__CLASS__);
     if (!Strings::startsWith($projectPath, '/')) {
         $projectPath = "/{$projectPath}";
     }
     if (Strings::endsWith($projectPath, '/')) {
         $projectPath = substr($projectPath, 0, strlen($projectPath) - 1);
     }
     $projects = explode('/job/', $projectPath);
     unset($projects[0]);
     $this->baseApiPath = '/';
     foreach ($projects as $project) {
         $projectEncoded = rawurlencode($project);
         $this->baseApiPath .= "job/{$projectEncoded}/";
     }
     $this->metadata = $this->getJson(array());
     if (!isset($this->metadata['buildable'])) {
         throw new \InvalidArgumentException("The project at path '{$this->baseApiPath}'' is disabled");
     }
     $this->setDefaultParameters();
 }
예제 #4
0
파일: Numbers.php 프로젝트: martinsv/bart
 /**
  * @return \Logger
  */
 private static function logger()
 {
     if (!self::$_logger) {
         self::$_logger = Log4PHP::getLogger(__CLASS__);
     }
     return self::$_logger;
 }
예제 #5
0
 /**
  * @param string $gitDir Full path to the git dir
  * @param string $projectName Name of repository
  * @param string $hookName Current hook
  */
 private function __construct($gitDir, $projectName, $hookName)
 {
     $this->gitRoot = Diesel::create('\\Bart\\Git\\GitRoot', $gitDir);
     $this->gitDir = $gitDir;
     $this->projectName = $projectName;
     $this->hookName = $hookName;
     $this->logger = Log4PHP::getLogger(__CLASS__);
 }
예제 #6
0
 /**
  * @param array $hookConf Configuration for this hook type
  * @param string $repo Name of the repository
  */
 public function __construct(array $hookConf, $gitDir, $repo)
 {
     $this->hookConf = $hookConf;
     $this->repo = $repo;
     $this->logger = Log4PHP::getLogger(get_called_class());
     /** @var \Bart\Git git handle to current project */
     $this->git = Diesel::create('Bart\\Git', $gitDir);
 }
예제 #7
0
파일: Command.php 프로젝트: martinsv/bart
 /**
  * @param string $commandFormat Command string to run. Use printf like placeholders for argument
  * WARNING Only STRINGS supported. This is due to escapeshellcommand converting everything to a string.
  * @param string $args, ... [Optional] All arguments
  * @warning Do NOT single-quote any arg placeholders in $commandFormat. This will be done by
  * the class itself and placing single-quotes in the command string will negate this work.
  */
 public function __construct($commandFormat)
 {
     $this->logger = Log4PHP::getLogger(__CLASS__);
     $safeCommandFormat = escapeshellcmd($commandFormat);
     $args = func_get_args();
     array_shift($args);
     // bump off the format string from the front
     $this->safeCommandStr = self::makeSafeString($safeCommandFormat, $args);
     $this->logger->debug('Set safe command string ' . $this->safeCommandStr);
 }
예제 #8
0
파일: Job.php 프로젝트: shahbhavya85/bart
 /**
  * Load metadata about a project
  */
 public function __construct($domain, $job_name)
 {
     if (!$domain) {
         throw new \Exception('Must provide a valid domain');
     }
     if (!$job_name) {
         throw new \Exception('Must provide a job name');
     }
     $this->logger = Log4PHP::getLogger(__CLASS__);
     $this->base_job_url = "http://{$domain}:8080/job/" . rawurlencode($job_name) . '/';
     $this->logger->debug('Base uri: ' . $this->base_job_url);
     $this->metadata = $this->get_json(array());
     if (!$this->metadata['buildable']) {
         throw new \Exception("Project {$job_name} is disabled");
     }
     $this->set_default_params();
 }
예제 #9
0
 /**
  * Connection constructor.
  * @param string $domain
  * @param string $protocol 'http' or 'https'.
  * @param int $port The port can be generally be determined by the $protocol. 'http' corresponds
  * to port 8080, while 'https' corresponds to 443. If the $port is passed in, it will override
  * that determination.
  */
 public function __construct($domain, $protocol = 'http', $port = null)
 {
     if (!in_array($protocol, ['http', 'https'])) {
         throw new \InvalidArgumentException("The protocol must only be 'http' or 'https'");
     }
     $this->logger = Log4PHP::getLogger(__CLASS__);
     $this->curlOptions = [];
     $this->port = $port;
     if ($this->port === null) {
         if ($protocol === 'http') {
             $this->port = 8080;
         } else {
             $this->port = 443;
         }
     }
     $this->baseUrl = "{$protocol}://{$domain}:{$this->port}";
     $this->logger->debug('Base URL: ' . $this->baseUrl);
 }
예제 #10
0
파일: setup.php 프로젝트: martinsv/bart
<?php

error_reporting(E_ALL | E_STRICT);
// $root/test/setup.php
$root = dirname(__DIR__) . '/';
require_once $root . 'src/Bart/bart-common.php';
require_once $root . 'vendor/autoload.php';
// So tests can use static methods in other tests
\Bart\Autoloader::register_autoload_path($root . 'test');
date_default_timezone_set('America/Los_Angeles');
require_once $root . 'test/Bart/BaseTestCase.php';
// If you don't want to use log4php, then we can create a stub class for it;
// ...but at the time being, it's not a priority
\Bart\Log4PHP::initForConsole('off');
예제 #11
0
파일: Change.php 프로젝트: martinsv/bart
 /**
  * @param string $changeId Gerrit Change-Id key
  */
 public function __construct($changeId)
 {
     $this->api = Diesel::create('\\Bart\\Gerrit\\Api');
     $this->changeId = $changeId;
     $this->logger = Log4PHP::getLogger(__CLASS__);
 }
예제 #12
0
 /**
  * Instantiate instance configured to load configurations based on called class name
  */
 public function __construct()
 {
     $this->logger = Log4PHP::getLogger(get_called_class());
     $this->load();
 }
예제 #13
0
 /**
  * @param $pidFileLocation string Full path to where the pid file should be located, e.g. '/var/run/my-process.pid'
  */
 public function __construct($pidFileLocation)
 {
     $this->pidFileLocation = $pidFileLocation;
     $this->shell = Diesel::create('\\Bart\\Shell');
     $this->logger = Log4PHP::getLogger(__CLASS__);
 }