futuretek/php-gitlab-api

GitLab API 客户端

9.13.1 2019-10-24 12:26 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:^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 方法模型)并请随时报告任何错误。

框架集成

如果您将 GitLab 集成到了流行的 PHP 框架中,请让我们知道!

贡献

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