mirkoschmidt/php-gitlab-api

GitLab API客户端

v9.7.0 2018-09-10 13:40 UTC

README

Build Status StyleCI Total Downloads Latest Stable Version Latest Unstable Version

基于php-github-api和来自KnpLabs的代码。

安装

通过composer

composer require m4tthumphrey/php-gitlab-api php-http/guzzle6-adapter

为什么使用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)
;

$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方法模型),并请随时报告任何错误。

框架集成

如果您已经将GitLab集成到流行的PHP框架中,请告诉我们!

贡献

Gitlab的许多部分我没有添加到这个中,因为它最初是为了个人使用而创建的,因此缺少测试。请随意分支并添加新功能和测试,我将很高兴接受合理的拉取请求。