├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── config └── youtrack.php └── src └── YouTrackServiceProvider.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `cybercog/laravel-youtrack-sdk` will be documented in this file. 4 | 5 | ## [Unreleased] 6 | 7 | ## [6.0.0] - 2024-02-22 8 | 9 | ### Added 10 | 11 | - Guzzle 7 support 12 | 13 | ### Removed 14 | 15 | - Dropped PHP <= 8.0 support 16 | - Dropped Guzzle 6 support 17 | 18 | ## [5.3.0] - 2020-09-13 19 | 20 | ### Added 21 | 22 | - ([#13]) Laravel 8 support 23 | 24 | ## [5.2.0] - 2020-03-07 25 | 26 | ### Added 27 | 28 | - ([#12]) Laravel 7 support 29 | 30 | ## [5.1.0] - 2019-09-04 31 | 32 | ### Added 33 | 34 | - ([#9]) Laravel 6 support 35 | 36 | ## [5.0.0] - 2019-03-18 37 | 38 | ### Added 39 | 40 | - Laravel 5.8 support 41 | 42 | ### Removed 43 | 44 | - Laravel 5.4, 5.5, 5.6, 5.7 support 45 | 46 | ### Changed 47 | 48 | - Make all classes final 49 | - Moved service provider from `Cog\Laravel\YouTrack\Providers\YouTrackServiceProvider` to `Cog\Laravel\YouTrack\YouTrackServiceProvider` 50 | 51 | ## [4.2.0] - 2018-09-09 52 | 53 | ### Added 54 | 55 | - Laravel 5.7 support 56 | 57 | ## [4.1.0] - 2018-02-08 58 | 59 | ### Added 60 | 61 | - Laravel 5.6 support 62 | 63 | ### Removed 64 | 65 | - Laravel 5.1 support 66 | - Laravel 5.2 support 67 | - Laravel 5.3 support 68 | 69 | ## [4.0.0] - 2017-11-20 70 | 71 | ### Changed 72 | 73 | - Updated PHP YouTrack SDK major version to 4.0.0 74 | 75 | ## [3.0.0] - 2017-09-13 76 | 77 | ### Changed 78 | 79 | - Updated PHP YouTrack SDK major version to 3.0.0 80 | 81 | ## [2.0.0] - 2017-08-27 82 | 83 | ### Changed 84 | 85 | - Updated PHP YouTrack SDK major version to 2.0.0 86 | 87 | ## 1.0.0 - 2017-05-22 88 | 89 | - Initial release 90 | 91 | [Unreleased]: https://github.com/cybercog/laravel-youtrack-sdk/compare/6.0.0...master 92 | [6.0.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/5.3.0...6.0.0 93 | [5.3.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/5.2.0...5.3.0 94 | [5.2.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/5.1.0...5.2.0 95 | [5.1.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/5.0.0...5.1.0 96 | [5.0.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/4.2.0...5.0.0 97 | [4.2.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/4.1.0...4.2.0 98 | [4.1.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/4.0.0...4.1.0 99 | [4.0.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/3.0.0...4.0.0 100 | [3.0.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/2.0.0...3.0.0 101 | [2.0.0]: https://github.com/cybercog/laravel-youtrack-sdk/compare/1.0.0...2.0.0 102 | 103 | [#13]: https://github.com/cybercog/laravel-youtrack-sdk/pull/13 104 | [#12]: https://github.com/cybercog/laravel-youtrack-sdk/pull/12 105 | [#9]: https://github.com/cybercog/laravel-youtrack-sdk/pull/9 106 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020, Anton Komarev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel YouTrack SDK 2 | 3 | ![cog-laravel-youtrack-sdk](https://cloud.githubusercontent.com/assets/1849174/26226734/98de7ac6-3c36-11e7-9017-4c0f2151ec81.png) 4 | 5 |

6 | Build Status 7 | StyleCI 8 | Code Climate 9 | Releases 10 | License 11 |

12 | 13 | ## Introduction 14 | 15 | Laravel wrapper for the [PHP YouTrack SDK](https://github.com/cybercog/youtrack-php-sdk#readme) library provides set of tools to interact with [JetBrains YouTrack Issue Tracking and Project Management software](https://www.jetbrains.com/youtrack/). 16 | 17 | ## Contents 18 | 19 | - [Features](#features) 20 | - [Requirements](#requirements) 21 | - [Installation](#installation) 22 | - [Configuration](#configuration) 23 | - [YouTrack URL](#youtrack-url) 24 | - [Authorization methods](#authorization-methods) 25 | - [Usage](#usage) 26 | - [Initialize API client](#initialize-api-client) 27 | - [API requests](#api-requests) 28 | - [API responses](#api-responses) 29 | - [Changelog](#changelog) 30 | - [Contributing](#contributing) 31 | - [Testing](#testing) 32 | - [Security](#security) 33 | - [Contributors](#contributors) 34 | - [Alternatives](#alternatives) 35 | - [License](#license) 36 | - [About CyberCog](#about-cybercog) 37 | 38 | ## Features 39 | 40 | - Using contracts to keep high customization capabilities. 41 | - Multiple authorization strategies: Token, Cookie. 42 | - Following PHP Standard Recommendations: 43 | - [PSR-1 (Basic Coding Standard)](http://www.php-fig.org/psr/psr-1/). 44 | - [PSR-2 (Coding Style Guide)](http://www.php-fig.org/psr/psr-2/). 45 | - [PSR-4 (Autoloading Standard)](http://www.php-fig.org/psr/psr-4/). 46 | - [PSR-7 (HTTP Message Interface)](http://www.php-fig.org/psr/psr-7/). 47 | - Covered with unit tests. 48 | 49 | ## Requirements 50 | 51 | - YouTrack >= 3.0 with REST-API enabled (always enabled, by default) 52 | - PHP >= 8.1 53 | - Guzzle HTTP Client >= 7.0 54 | - Laravel >= 5.1.20 55 | 56 | ## Installation 57 | 58 | The preferred method is via [composer](https://getcomposer.org). Follow the 59 | [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have 60 | composer installed. 61 | 62 | Once composer is installed, execute the following command in your project root to install this library: 63 | 64 | ```shell 65 | composer require cybercog/laravel-youtrack-sdk 66 | ``` 67 | 68 | ## Configuration 69 | 70 | Laravel YouTrack SDK designed to work with default config, but it always could be modified. First of all publish it: 71 | 72 | ```shell 73 | php artisan vendor:publish --tag="youtrack-config" 74 | ``` 75 | 76 | This will create a `config/youtrack.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases. 77 | 78 | ### YouTrack URL 79 | 80 | YouTrack instance location could be defined in `.env` file: 81 | 82 | ```dotenv 83 | YOUTRACK_BASE_URI=https://youtrack.custom.domain 84 | ``` 85 | 86 | ### Authorization methods 87 | 88 | Starting with YouTrack 2017.1 release [authorization based on permanent tokens](https://www.jetbrains.com/help/youtrack/standalone/2017.2/Manage-Permanent-Token.html) is recommended as the main approach for the authorization in your REST API calls. 89 | 90 | By default Token authorization will be used. You could redefine it in `.env` file: 91 | 92 | #### Token authorization 93 | 94 | ```dotenv 95 | YOUTRACK_AUTH=token 96 | YOUTRACK_TOKEN=your-permanents-token 97 | ``` 98 | 99 | #### Cookie authorization 100 | 101 | ```dotenv 102 | YOUTRACK_AUTH=cookie 103 | YOUTRACK_USERNAME=username 104 | YOUTRACK_PASSWORD=secret 105 | ``` 106 | 107 | ## Usage 108 | 109 | ### Initialize API client 110 | 111 | ```php 112 | $youtrack = app(\Cog\Contracts\YouTrack\Rest\Client\Client::class); 113 | ``` 114 | 115 | As result instantiated `\Cog\YouTrack\Rest\Client\YouTrackClient` class should be returned. 116 | 117 | ### API requests 118 | 119 | #### HTTP request 120 | 121 | ```php 122 | $method = 'POST'; // GET, POST, PUT, DELETE, PATCH or any custom ones 123 | $response = $youtrack->request($method, '/issue', [ 124 | 'project' => 'TEST', 125 | 'summary' => 'New test issue', 126 | 'description' => 'Test description', 127 | ]); 128 | ``` 129 | 130 | You can [customize requests created and transferred by a client using request options](http://docs.guzzlephp.org/en/latest/request-options.html). Request options control various aspects of a request including, headers, query string parameters, timeout settings, the body of a request, and much more. 131 | 132 | ```php 133 | $options = [ 134 | 'debug' => true, 135 | 'sink' => '/path/to/dump/file', 136 | ]; 137 | $response = $youtrack->request('POST', '/issue', [ 138 | 'project' => 'TEST', 139 | 'summary' => 'New test issue', 140 | 'description' => 'Test description', 141 | ], $options); 142 | ``` 143 | 144 | #### HTTP GET request 145 | 146 | ```php 147 | $response = $youtrack->get('/issue/TEST-1'); 148 | ``` 149 | 150 | #### HTTP POST request 151 | 152 | ```php 153 | $response = $youtrack->post('/issue', [ 154 | 'project' => 'TEST', 155 | 'summary' => 'New test issue', 156 | 'description' => 'Test description', 157 | ]); 158 | ``` 159 | 160 | #### HTTP PUT request 161 | 162 | ```php 163 | $response = $youtrack->put('/issue/TEST-1', [ 164 | 'summary' => 'Updated summary', 165 | 'description' => 'Updated description', 166 | ]); 167 | ``` 168 | 169 | #### HTTP DELETE request 170 | 171 | ```php 172 | $response = $youtrack->delete('/issue/TEST-1'); 173 | ``` 174 | 175 | ### API responses 176 | 177 | Each successful request to the API returns instance of `\Cog\Contracts\YouTrack\Rest\Response\Response` contract. By default it's `\Cog\YouTrack\Rest\Response\YouTrackResponse` class. 178 | 179 | #### Get PSR HTTP response 180 | 181 | PSR HTTP response could be accessed by calling `httpResponse` method on API Response. 182 | 183 | ```php 184 | $youtrackResponse = $youtrack->get('/issue/TEST-1'); 185 | $psrResponse = $youtrackResponse->httpResponse(); 186 | ``` 187 | 188 | #### Get response Cookie 189 | 190 | Returns `Set-Cookie` headers as string from the HTTP response. 191 | 192 | ```php 193 | $apiResponse = $youtrack->get('/issue/TEST-1'); 194 | $cookieString = $apiResponse->cookie(); 195 | ``` 196 | 197 | #### Get response Location 198 | 199 | Returns `Location` header from the HTTP response. 200 | 201 | ```php 202 | $apiResponse = $youtrack->get('/issue/TEST-1'); 203 | $location = $apiResponse->location(); 204 | ``` 205 | 206 | #### Transform response to array 207 | 208 | ```php 209 | $apiResponse = $youtrack->get('/issue/TEST-1'); 210 | $location = $apiResponse->toArray(); 211 | ``` 212 | 213 | #### Get HTTP response status code 214 | 215 | ```php 216 | $apiResponse = $youtrack->get('/issue/TEST-1'); 217 | $location = $apiResponse->statusCode(); 218 | ``` 219 | 220 | ## Changelog 221 | 222 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 223 | 224 | ## Contributing 225 | 226 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 227 | 228 | ## Testing 229 | 230 | Run the tests with: 231 | 232 | ```shell 233 | vendor/bin/phpunit 234 | ``` 235 | 236 | ## Security 237 | 238 | If you discover any security related issues, please email open@cybercog.su instead of using the issue tracker. 239 | 240 | ## Contributors 241 | 242 | | ![@antonkomarev](https://avatars.githubusercontent.com/u/1849174?s=110)
Anton Komarev
| sergiy-petrov | 243 | | :---: | :---: | 244 | 245 | [Laravel YouTrack SDK contributors list](../../contributors) 246 | 247 | ## Alternatives 248 | 249 | Alternatives not found. 250 | 251 | *Feel free to add more alternatives as Pull Request.* 252 | 253 | ## License 254 | 255 | - `Laravel YouTrack SDK` package is open-sourced software licensed under the [MIT License](LICENSE) by [Anton Komarev]. 256 | 257 | ## About CyberCog 258 | 259 | [CyberCog](https://cybercog.su) is a Social Unity of enthusiasts. Research best solutions in product & software development is our passion. 260 | 261 | - [Follow us on Twitter](https://twitter.com/cybercog) 262 | - [Read our articles on Medium](https://medium.com/cybercog) 263 | 264 | CyberCog 265 | 266 | [Anton Komarev]: https://komarev.com 267 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cybercog/laravel-youtrack-sdk", 3 | "description": "Laravel wrapper for PHP YouTrack SDK.", 4 | "type": "library", 5 | "license": "MIT", 6 | "keywords": [ 7 | "cybercog", 8 | "cog", 9 | "laravel", 10 | "youtrack", 11 | "yt", 12 | "sdk", 13 | "rest", 14 | "api", 15 | "client", 16 | "jetbrains", 17 | "issues", 18 | "bugtracker", 19 | "helpdesk", 20 | "pm", 21 | "tickets" 22 | ], 23 | "authors": [ 24 | { 25 | "name": "Anton Komarev", 26 | "email": "anton@komarev.com", 27 | "homepage": "https://komarev.com", 28 | "role": "Developer" 29 | } 30 | ], 31 | "homepage": "https://github.com/cybercog/laravel-youtrack-sdk", 32 | "support": { 33 | "email": "open@cybercog.su", 34 | "issues": "https://github.com/cybercog/laravel-youtrack-sdk/issues", 35 | "wiki": "https://github.com/cybercog/youtrack-php-sdk/wiki", 36 | "source": "https://github.com/cybercog/laravel-youtrack-sdk", 37 | "docs": "https://github.com/cybercog/youtrack-php-sdk/wiki" 38 | }, 39 | "require": { 40 | "php": "^8.1", 41 | "cybercog/youtrack-php-sdk": "^5.0", 42 | "illuminate/support": "^5.8|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0" 43 | }, 44 | "require-dev": { 45 | "orchestra/testbench": "^3.8|^4.0|^5.0|^6.0", 46 | "phpunit/phpunit": "^7.0|^8.0|^9.0" 47 | }, 48 | "autoload": { 49 | "psr-4": { 50 | "Cog\\Laravel\\YouTrack\\": "src/" 51 | } 52 | }, 53 | "autoload-dev": { 54 | "psr-4": { 55 | "Cog\\Tests\\Laravel\\YouTrack\\": "tests/" 56 | } 57 | }, 58 | "scripts": { 59 | "test": "vendor/bin/phpunit" 60 | }, 61 | "config": { 62 | "sort-packages": true 63 | }, 64 | "extra": { 65 | "laravel": { 66 | "providers": [ 67 | "Cog\\Laravel\\YouTrack\\YouTrackServiceProvider" 68 | ] 69 | } 70 | }, 71 | "minimum-stability": "dev", 72 | "prefer-stable" : true 73 | } 74 | -------------------------------------------------------------------------------- /config/youtrack.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 | | YouTrack Base URI 19 | |-------------------------------------------------------------------------- 20 | | 21 | | Indicates base URI of the YouTrack instance. 22 | | 23 | */ 24 | 25 | 'base_uri' => env('YOUTRACK_BASE_URI'), 26 | 27 | /* 28 | |-------------------------------------------------------------------------- 29 | | Default YouTrack Authorizer Name 30 | |-------------------------------------------------------------------------- 31 | | 32 | | This option controls the default authorizer that will be used by the 33 | | library when YouTrack authorization is required. You may set this to 34 | | any of the drivers defined in the "authorizers" array below. 35 | | 36 | | Supported: "token" (recommended), "cookie" 37 | | 38 | */ 39 | 40 | 'authorizer' => env('YOUTRACK_AUTH', 'token'), 41 | 42 | /* 43 | |-------------------------------------------------------------------------- 44 | | YouTrack Authorizers 45 | |-------------------------------------------------------------------------- 46 | | 47 | | Here are each of the authorizers available in YouTrack REST API. 48 | | 49 | */ 50 | 51 | 'authorizers' => [ 52 | 'token' => [ 53 | 'driver' => \Cog\YouTrack\Rest\Authorizer\TokenAuthorizer::class, 54 | 'token' => env('YOUTRACK_TOKEN'), 55 | ], 56 | 57 | 'cookie' => [ 58 | 'driver' => \Cog\YouTrack\Rest\Authorizer\CookieAuthorizer::class, 59 | 'username' => env('YOUTRACK_USERNAME'), 60 | 'password' => env('YOUTRACK_PASSWORD'), 61 | ], 62 | ], 63 | ]; 64 | -------------------------------------------------------------------------------- /src/YouTrackServiceProvider.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 Cog\Laravel\YouTrack; 15 | 16 | use Cog\Contracts\YouTrack\Rest\Authorizer\Authorizer as AuthorizerContract; 17 | use Cog\Contracts\YouTrack\Rest\Client\Client as ClientContract; 18 | use Cog\YouTrack\Rest\Authenticator\CookieAuthenticator; 19 | use Cog\YouTrack\Rest\Client\YouTrackClient; 20 | use Cog\YouTrack\Rest\HttpClient\GuzzleHttpClient; 21 | use GuzzleHttp\Client as HttpClient; 22 | use Illuminate\Contracts\Config\Repository as ConfigContract; 23 | use Illuminate\Foundation\Application as LaravelApplication; 24 | use Illuminate\Support\ServiceProvider; 25 | use Laravel\Lumen\Application as LumenApplication; 26 | 27 | final class YouTrackServiceProvider extends ServiceProvider 28 | { 29 | public function register(): void 30 | { 31 | $this->registerBindings(); 32 | } 33 | 34 | public function boot(): void 35 | { 36 | $this->bootConfig(); 37 | } 38 | 39 | private function registerBindings(): void 40 | { 41 | $this->app->bind(ClientContract::class, function () { 42 | $config = $this->app->make(ConfigContract::class); 43 | 44 | $httpClient = new GuzzleHttpClient(new HttpClient([ 45 | 'base_uri' => $config->get('youtrack.base_uri'), 46 | ])); 47 | 48 | return new YouTrackClient($httpClient, $this->resolveAuthorizerDriver($config)); 49 | }); 50 | } 51 | 52 | private function bootConfig(): void 53 | { 54 | $source = realpath(__DIR__ . '/../config/youtrack.php'); 55 | 56 | if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { 57 | $this->publishes([$source => config_path('youtrack.php')], 'youtrack-config'); 58 | } elseif ($this->app instanceof LumenApplication) { 59 | $this->app->configure('youtrack'); 60 | } 61 | 62 | $this->mergeConfigFrom($source, 'youtrack'); 63 | } 64 | 65 | private function resolveAuthorizerDriver(ConfigContract $config): AuthorizerContract 66 | { 67 | $authorizer = $config->get('youtrack.authorizer'); 68 | 69 | $options = $config->get('youtrack.authorizers.' . $authorizer); 70 | if ($authorizer === 'cookie') { 71 | return new $options['driver']( 72 | new CookieAuthenticator($options['username'], $options['password']) 73 | ); 74 | } 75 | 76 | return new $options['driver']($options['token']); 77 | } 78 | } 79 | --------------------------------------------------------------------------------