benmag / php-gitlab-api
GitLab API 客户端
9.12.0
2019-02-03 22:34 UTC
Requires
- php: ^5.6 || ^7.0
- ext-xml: *
- php-http/client-common: ^1.6
- php-http/client-implementation: ^1.0
- 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
This package is auto-updated.
Last update: 2024-08-29 04:14:36 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 for library users 了解更多有关安装与 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 的许多功能,因此测试较少。请随意分支并添加新功能及测试,我将很高兴接受合理的 pull request。