├── .styleci.yml ├── LICENSE ├── composer.json ├── config └── gitlab.php └── src ├── Facades └── GitLab.php ├── GitLabFactory.php ├── GitLabManager.php └── GitLabServiceProvider.php /.styleci.yml: -------------------------------------------------------------------------------- 1 | enabled: 2 | - unalign_double_arrow 3 | 4 | disabled: 5 | - align_double_arrow 6 | - phpdoc_align 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Vincent Klaiber 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vinkla/gitlab", 3 | "description": "A GitLab bridge for Laravel", 4 | "license": "MIT", 5 | "keywords": ["laravel", "gitlab", "git", "api"], 6 | "authors": [ 7 | { 8 | "name": "Vincent Klaiber", 9 | "email": "hello@vinkla.com", 10 | "homepage": "https://vinkla.com" 11 | } 12 | ], 13 | "require": { 14 | "php": "^7.0", 15 | "illuminate/contracts": "5.5.*", 16 | "illuminate/support": "5.5.*", 17 | "graham-campbell/manager": "^3.0", 18 | "m4tthumphrey/php-gitlab-api": "^9.0" 19 | }, 20 | "require-dev": { 21 | "graham-campbell/analyzer": "^1.1", 22 | "graham-campbell/testbench": "^4.0", 23 | "mockery/mockery": "^1.0", 24 | "orchestra/testbench": "^3.5", 25 | "php-http/guzzle6-adapter": "^1.0", 26 | "phpunit/phpunit": "^6.3" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "Vinkla\\GitLab\\": "src/" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "Vinkla\\Tests\\GitLab\\": "tests/" 36 | } 37 | }, 38 | "config": { 39 | "preferred-install": "dist" 40 | }, 41 | "extra": { 42 | "branch-alias": { 43 | "dev-master": "4.1-dev" 44 | }, 45 | "laravel": { 46 | "providers": [ 47 | "Vinkla\\GitLab\\GitLabServiceProvider" 48 | ], 49 | "aliases": { 50 | "GitLab": "Vinkla\\GitLab\\Facades\\GitLab" 51 | } 52 | } 53 | }, 54 | "minimum-stability": "dev", 55 | "prefer-stable": true 56 | } 57 | -------------------------------------------------------------------------------- /config/gitlab.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | return [ 15 | 16 | /* 17 | |-------------------------------------------------------------------------- 18 | | Default Connection Name 19 | |-------------------------------------------------------------------------- 20 | | 21 | | Here you may specify which of the connections below you wish to use as 22 | | your default connection for all work. Of course, you may use many 23 | | connections at once using the manager class. 24 | | 25 | */ 26 | 27 | 'default' => 'main', 28 | 29 | /* 30 | |-------------------------------------------------------------------------- 31 | | GitLab Connections 32 | |-------------------------------------------------------------------------- 33 | | 34 | | Here are each of the connections setup for your application. Example 35 | | configuration has been included, but you may add as many connections as 36 | | you would like. 37 | | 38 | */ 39 | 40 | 'connections' => [ 41 | 42 | 'main' => [ 43 | 'token' => 'your-token', 44 | 'url' => 'https://git.yourdomain.com', 45 | ], 46 | 47 | 'alternative' => [ 48 | 'token' => 'your-token', 49 | 'url' => 'https://git.yourdomain.com', 50 | ], 51 | 52 | ], 53 | 54 | ]; 55 | -------------------------------------------------------------------------------- /src/Facades/GitLab.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Vinkla\GitLab\Facades; 15 | 16 | use Illuminate\Support\Facades\Facade; 17 | 18 | /** 19 | * This is the GitLab facade class. 20 | * 21 | * @author Vincent Klaiber 22 | */ 23 | class GitLab extends Facade 24 | { 25 | /** 26 | * Get the registered name of the component. 27 | * 28 | * @return string 29 | */ 30 | protected static function getFacadeAccessor(): string 31 | { 32 | return 'gitlab'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/GitLabFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Vinkla\GitLab; 15 | 16 | use Gitlab\Client; 17 | use InvalidArgumentException; 18 | 19 | /** 20 | * This is the gitlab factory class. 21 | * 22 | * @author Vincent Klaiber 23 | */ 24 | class GitLabFactory 25 | { 26 | /** 27 | * Make a new gitlab client. 28 | * 29 | * @param array $config 30 | * 31 | * @return \Gitlab\Client 32 | */ 33 | public function make(array $config): Client 34 | { 35 | $config = $this->getConfig($config); 36 | 37 | return $this->getClient($config); 38 | } 39 | 40 | /** 41 | * Get the configuration data. 42 | * 43 | * @param string[] $config 44 | * 45 | * @throws \InvalidArgumentException 46 | * 47 | * @return array 48 | */ 49 | protected function getConfig(array $config): array 50 | { 51 | $keys = ['token', 'url']; 52 | 53 | foreach ($keys as $key) { 54 | if (!array_key_exists($key, $config)) { 55 | throw new InvalidArgumentException("Missing configuration key [$key]."); 56 | } 57 | } 58 | 59 | return array_only($config, ['token', 'url', 'method', 'sudo']); 60 | } 61 | 62 | /** 63 | * Get the main client. 64 | * 65 | * @param array $config 66 | * 67 | * @return \Gitlab\Client 68 | */ 69 | protected function getClient(array $config): Client 70 | { 71 | $client = Client::create($config['url']); 72 | 73 | $client->authenticate( 74 | $config['token'], 75 | array_get($config, 'method', Client::AUTH_URL_TOKEN), 76 | array_get($config, 'sudo', null) 77 | ); 78 | 79 | return $client; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/GitLabManager.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Vinkla\GitLab; 15 | 16 | use Gitlab\Client; 17 | use GrahamCampbell\Manager\AbstractManager; 18 | use Illuminate\Contracts\Config\Repository; 19 | 20 | /** 21 | * This is the gitlab manager class. 22 | * 23 | * @author Vincent Klaiber 24 | */ 25 | class GitLabManager extends AbstractManager 26 | { 27 | /** 28 | * The factory instance. 29 | * 30 | * @var \Vinkla\GitLab\GitLabFactory 31 | */ 32 | private $factory; 33 | 34 | /** 35 | * Create a new gitlab manager instance. 36 | * 37 | * @param \Illuminate\Contracts\Config\Repository $config 38 | * @param \Vinkla\GitLab\GitLabFactory $factory 39 | * 40 | * @return void 41 | */ 42 | public function __construct(Repository $config, GitLabFactory $factory) 43 | { 44 | parent::__construct($config); 45 | 46 | $this->factory = $factory; 47 | } 48 | 49 | /** 50 | * Create the connection instance. 51 | * 52 | * @param array $config 53 | * 54 | * @return \Gitlab\Client 55 | */ 56 | protected function createConnection(array $config): Client 57 | { 58 | return $this->factory->make($config); 59 | } 60 | 61 | /** 62 | * Get the configuration name. 63 | * 64 | * @return string 65 | */ 66 | protected function getConfigName(): string 67 | { 68 | return 'gitlab'; 69 | } 70 | 71 | /** 72 | * Get the factory instance. 73 | * 74 | * @return \Vinkla\GitLab\GitLabFactory 75 | */ 76 | public function getFactory(): GitLabFactory 77 | { 78 | return $this->factory; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/GitLabServiceProvider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Vinkla\GitLab; 15 | 16 | use Gitlab\Client; 17 | use Illuminate\Contracts\Container\Container; 18 | use Illuminate\Foundation\Application as LaravelApplication; 19 | use Illuminate\Support\ServiceProvider; 20 | use Laravel\Lumen\Application as LumenApplication; 21 | 22 | /** 23 | * This is the GitLab service provider class. 24 | * 25 | * @author Vincent Klaiber 26 | */ 27 | class GitLabServiceProvider extends ServiceProvider 28 | { 29 | /** 30 | * Boot the service provider. 31 | * 32 | * @return void 33 | */ 34 | public function boot() 35 | { 36 | $this->setupConfig(); 37 | } 38 | 39 | /** 40 | * Setup the config. 41 | * 42 | * @return void 43 | */ 44 | protected function setupConfig() 45 | { 46 | $source = realpath(__DIR__.'/../config/gitlab.php'); 47 | 48 | if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { 49 | $this->publishes([$source => config_path('gitlab.php')]); 50 | } elseif ($this->app instanceof LumenApplication) { 51 | $this->app->configure('gitlab'); 52 | } 53 | 54 | $this->mergeConfigFrom($source, 'gitlab'); 55 | } 56 | 57 | /** 58 | * Register the service provider. 59 | * 60 | * @return void 61 | */ 62 | public function register() 63 | { 64 | $this->registerFactory(); 65 | $this->registerManager(); 66 | $this->registerBindings(); 67 | } 68 | 69 | /** 70 | * Register the factory class. 71 | * 72 | * @return void 73 | */ 74 | protected function registerFactory() 75 | { 76 | $this->app->singleton('gitlab.factory', function () { 77 | return new GitLabFactory(); 78 | }); 79 | 80 | $this->app->alias('gitlab.factory', GitLabFactory::class); 81 | } 82 | 83 | /** 84 | * Register the manager class. 85 | * 86 | * @return void 87 | */ 88 | protected function registerManager() 89 | { 90 | $this->app->singleton('gitlab', function (Container $app) { 91 | $config = $app['config']; 92 | $factory = $app['gitlab.factory']; 93 | 94 | return new GitLabManager($config, $factory); 95 | }); 96 | 97 | $this->app->alias('gitlab', GitLabManager::class); 98 | } 99 | 100 | /** 101 | * Register the bindings. 102 | * 103 | * @return void 104 | */ 105 | protected function registerBindings() 106 | { 107 | $this->app->bind('gitlab.connection', function (Container $app) { 108 | $manager = $app['gitlab']; 109 | 110 | return $manager->connection(); 111 | }); 112 | 113 | $this->app->alias('gitlab.connection', Client::class); 114 | } 115 | 116 | /** 117 | * Get the services provided by the provider. 118 | * 119 | * @return string[] 120 | */ 121 | public function provides(): array 122 | { 123 | return [ 124 | 'gitlab', 125 | 'gitlab.factory', 126 | 'gitlab.connection', 127 | ]; 128 | } 129 | } 130 | --------------------------------------------------------------------------------