futuretek / php-gitlab-api
GitLab API 客户端
9.13.1
2019-10-24 12:26 UTC
Requires
- php: ^5.6 || ^7.0
- ext-xml: *
- php-http/client-common: ^1.6
- php-http/discovery: ^1.2
- php-http/httplug: ^1.1
- php-http/multipart-stream-builder: ^1.0
- symfony/options-resolver: ^2.6 || ^3.0 || ^4.0
Requires (Dev)
- guzzlehttp/psr7: ^1.2
- php-http/guzzle6-adapter: ^1.0
- php-http/mock-client: ^1.0
- phpunit/phpunit: ^5.7.27 || ^6.5
- dev-master / 9.14.x-dev
- 9.13.1
- 9.13.0
- 9.12.0
- 9.11.0
- 9.10.0
- 9.9.0
- 9.8.0
- 9.7.0
- 9.6.1
- 9.6.0
- 9.5.0
- 9.4.0
- 9.3.0
- 9.2.0
- 9.1.0
- 9.0.0
- 9.0.0-rc1
- 9.0.0-beta2
- 9.0.0-beta1
- 8.0.x-dev
- 8.0.0
- 7.15.0
- 7.14.0
- 7.13.1
- 7.13.0
- 7.11.0
- 7.10.0
- 7.9.0
- 7.8.0
- 6.9.1
- 6.9.0
- 6.4.3
- 6.2.2
- 6.2.1
- 6.2.0
- 6.1.0
- 6.0.0
- v4.x-dev
- 0.7.1
- 0.7.0
- 0.6.1
- 0.6.0
This package is auto-updated.
Last update: 2024-09-24 23:12:34 UTC
README
基于 php-github-api 以及 KnpLabs 的代码。
安装
通过 composer
composer require m4tthumphrey/php-gitlab-api php-http/guzzle6-adapter:^1.0
为什么使用 php-http/guzzle6-adapter
?我们在 HTTPlug 的帮助下解耦了任何 HTTP 消息客户端。
您可以访问 HTTPlug 以获取有关安装与 HTTPlug 相关包的更多信息。
版本控制
根据您的 GitLab 服务器版本,您必须选择此库的正确版本。请参考以下表格以选择正确的版本。
通用 API 使用
$client = \Gitlab\Client::create('http://git.yourdomain.com') ->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN) ; // or for OAuth2 (see https://github.com/m4tthumphrey/php-gitlab-api/blob/master/lib/Gitlab/HttpClient/Plugin/Authentication.php#L47) $client = \Gitlab\Client::create('http://gitlab.yourdomain.com') ->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_OAUTH_TOKEN) ; $project = $client->api('projects')->create('My Project', array( 'description' => 'This is a project', 'issues_enabled' => false ));
带有分页器的示例
用于获取所有已关闭的问题并使用分页(在 GitLab API 中)
$client = \Gitlab\Client::create('http://git.yourdomain.com') ->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN) ; $pager = new \Gitlab\ResultPager($client); $issues = $pager->fetchAll($client->api('issues'),'all',[null, ['state' => 'closed']]);
模型使用
您还可以以面向对象的方式使用此库
$client = \Gitlab\Client::create('http://git.yourdomain.com') ->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN) ; # Creating a new project $project = \Gitlab\Model\Project::create($client, 'My Project', array( 'description' => 'This is my project', 'issues_enabled' => false )); $project->addHook('http://mydomain.com/hook/push/1'); # Creating a new issue $project = new \Gitlab\Model\Project(1, $client); $issue = $project->createIssue('This does not work.', array( 'description' => 'This doesn\'t work properly. Please fix.', 'assignee_id' => 2 )); # Closing that issue $issue->close();
您应该明白了!请查看周围的内容(API 方法,模型)并请随时报告任何错误。
框架集成
- Symfony - https://github.com/Zeichen32/GitLabApiBundle
- Laravel - https://github.com/GrahamCampbell/Laravel-GitLab
如果您将 GitLab 集成到了流行的 PHP 框架中,请让我们知道!
贡献
GitLab 的许多部分我尚未添加到其中,因为它是为个人使用而创建的,因此缺少测试。请随意分支并添加新的功能和测试,我将很高兴接受合理的拉取请求。