Example #1
0
 /**
  * @param string $host
  * @param string $token
  * @param Client $client
  */
 public function __construct($host, $token = null, Client $client = null)
 {
     $this->client = $client ?: new Client($host);
     if ($token) {
         $this->client->authenticate($token, Client::AUTH_URL_TOKEN);
     }
     parent::__construct();
 }
Example #2
0
 /**
  * @throws \Exception
  *
  * @return bool
  */
 public function authenticate()
 {
     if (Configurator::AUTH_HTTP_TOKEN !== $this->configuration['authentication']['http-auth-type']) {
         throw new AdapterException('Authentication type for GitLab must be Token.');
     }
     $this->client->authenticate($this->configuration['authentication']['password-or-token'], Client::AUTH_HTTP_TOKEN);
     return true;
 }
 /**
  * ПОдготавливает клиент для работы с гитлабом
  *
  * @return Client
  *
  */
 protected function getGitLabClient()
 {
     if (null === $this->client) {
         $this->client = new Client($this->url);
         $this->client->authenticate($this->token);
     }
     return $this->client;
 }
 /**
  * Returns an authenticated API client.
  *
  * Requires optional Gitlab API client to be installed.
  *
  * @return Client
  */
 public function getApiClient()
 {
     if (!class_exists('\\Gitlab\\Client')) {
         throw new \LogicException(__METHOD__ . ' requires package m4tthumphrey/php-gitlab-api to be installed and autoloaded');
         // @codeCoverageIgnore
     }
     $client = new Client(rtrim($this->domain, '/') . self::PATH_API);
     return $client->authenticate($this->token->getToken(), Client::AUTH_OAUTH_TOKEN);
 }
Example #5
0
 protected function createMilestone($githubMilestone, $project)
 {
     $gitlabMilestone = null;
     if ($this->gitlabMilestones === null) {
         $this->gitlabMilestones = $this->gitlabClient->milestones->all($project['id'], 100);
     }
     foreach ($this->gitlabMilestones as $_gitlabMilestone) {
         if ($_gitlabMilestone['title'] === $githubMilestone['title']) {
             $gitlabMilestone = $_gitlabMilestone;
             break;
         }
     }
     if (empty($gitlabMilestone)) {
         $this->output("\t" . '[milestone] Create "' . $githubMilestone['title'] . '"', self::OUTPUT_SUCCESS);
         if (!$this->dry) {
             $this->gitlabClient->authenticate(GITLAB_ADMIN_TOKEN, \Gitlab\Client::AUTH_URL_TOKEN);
             $gitlabMilestone = $this->gitlabClient->milestones->create($project['id'], ['title' => $githubMilestone['title'], 'description' => $githubMilestone['description'], 'state' => self::resolveMilestoneState($githubMilestone['state']), 'due_date' => $githubMilestone['due_on']]);
         }
     }
     return $gitlabMilestone['id'];
 }
 public function register(Application $app)
 {
     $app['gitlab'] = $app->share(function () use($app) {
         if (!isset($app['gitlab.url'])) {
             throw new \Exception('gitlab.url undefined');
         }
         if (!isset($app['gitlab.key'])) {
             throw new \Exception('gitlab.key undefined');
         }
         $client = new \Gitlab\Client($app['gitlab.url']);
         // change here
         $client->authenticate($app['gitlab.key'], \Gitlab\Client::AUTH_URL_TOKEN);
         // change here
         return $client;
     });
 }
Example #7
0
 /**
  * @inheritdoc
  */
 public function saveGit()
 {
     $client = new Client($this->enterpriseUrl);
     $client->authenticate($this->authKey, Client::AUTH_URL_TOKEN);
     $projects = $client->getHttpClient()->get('projects/')->getContent();
     foreach ($projects as $data) {
         if ($data['path_with_namespace'] == $this->owner . '/' . $this->repository) {
             $id = $data['id'];
             break;
         }
     }
     if (!isset($id)) {
         throw new HttpException(404, "Repository " . $this->repository . " not found.");
     }
     /**
      * @var Project $project
      */
     $project = Project::fromArray($client, compact('id'));
     $project->updateFile($this->remotePath, $this->content, 'master', $this->comment);
     return true;
 }
Example #8
0
    if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && ($since = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) && $since >= $mtime) {
        header('HTTP/1.0 304 Not Modified');
    } else {
        readfile($file);
    }
    die;
};
// See ../confs/samples/gitlab.ini
$config_file = __DIR__ . '/../confs/gitlab.ini';
if (!file_exists($config_file)) {
    header('HTTP/1.0 500 Internal Server Error');
    die('confs/gitlab.ini missing');
}
$confs = parse_ini_file($config_file);
$client = new Client($confs['endpoint']);
$client->authenticate($confs['api_key'], Client::AUTH_URL_TOKEN);
$projects = $client->api('projects');
$repos = $client->api('repositories');
$validMethods = array('ssh', 'http');
if (isset($confs['method']) && in_array($confs['method'], $validMethods)) {
    define('method', $confs['method']);
} else {
    define('method', 'ssh');
}
/**
 * Retrieves some information about a project's composer.json
 *
 * @param array $project
 * @param string $ref commit id
 * @return array|false
 */
Example #9
0
 /**
  * Constructor
  *
  * @param Project $project
  */
 public function __construct(Project $project)
 {
     $this->project = $project;
     $this->client = new \Gitlab\Client('');
     $this->client->authenticate("", \Gitlab\Client::AUTH_URL_TOKEN);
 }
Example #10
0
 /**
  * @return \Gitlab\Client
  */
 protected function authenticate()
 {
     $client = new GitLab($this->gitLabUrl);
     $client->authenticate($this->gitLabToken, GitLab::AUTH_URL_TOKEN);
     return $client;
 }
Example #11
0
 /**
  * Get the main client.
  *
  * @param array $config
  *
  * @return \Gitlab\Client
  */
 protected function getClient(array $config)
 {
     $client = new Client(array_get($config, 'base_url', 'http://git.yourdomain.com/api/v3/'));
     $client->authenticate($config['token'], array_get($config, 'method', Client::AUTH_HTTP_TOKEN), array_get($config, 'sudo', null));
     return $client;
 }
Example #12
0
 private function getClient(Remote $remote)
 {
     $config = $this->getRemoteConfig($remote);
     $client = new Client(rtrim($config->getUrl(), '/') . '/api/v3/');
     $client->authenticate($config->getToken(), Client::AUTH_HTTP_TOKEN);
     return $client;
 }
Example #13
0
 public function let(Client $client)
 {
     $client->authenticate('foo', 'url_token')->shouldBeCalled();
     $this->beConstructedWith('http://foo.com', 'foo', $client);
 }
Example #14
0
 /**
  * Get the main client.
  *
  * @param array $config
  *
  * @return \Gitlab\Client
  */
 protected function getClient(array $config)
 {
     $client = new Client($config['base_url']);
     $client->authenticate($config['token'], array_get($config, 'method', Client::AUTH_HTTP_TOKEN), array_get($config, 'sudo', null));
     return $client;
 }