pselge-daparto/php-gitlab-api

PHP 的 GitLab API v4 客户端

10.1.3 2020-10-30 08:53 UTC

README

我们提供了一个现代的 GitLab API v4 PHP 客户端。

Build Status StyleCI Status Packagist Downloads Latest Version

它基于 php-github-api,由 KnpLabs 开发。因此,我们现在有针对以下服务的非常相似的客户端:

查看变更日志发布安全策略许可行为准则贡献指南

安装

此版本支持 PHP 7.1-7.4。要开始,只需使用 Composer 需求项目。您还需要安装提供 psr/http-client-implementationpsr/http-factory-implementation 的包。

标准安装

PHP 7.1+

$ composer require pselge-daparto/php-gitlab-api:^10.1 php-http/guzzle6-adapter:^2.0.1 http-interop/http-factory-guzzle:^1.0

PHP 7.2+

$ composer require pselge-daparto/php-gitlab-api:^10.1 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0

框架集成

Laravel 6+

$ composer require graham-campbell/gitlab:^4.2 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0

Symfony 4

$ composer require zeichen32/gitlabapibundle:^5.0 symfony/http-client:^4.4 nyholm/psr7:^1.3

Symfony 5

$ composer require zeichen32/gitlabapibundle:^5.0 symfony/http-client:^5.0 nyholm/psr7:^1.3

我们使用 PSR-7PSR-17PSR-18HTTPlug 与任何 HTTP 消息客户端解耦。您可以访问 HTTPlug 获取有关安装 HTTPlug 相关包的更多信息。框架集成 graham-campbell/gitlabGraham Campbell 提供,而 zeichen32/gitlabapibundleJens Averkamp 提供。

通用 API 使用

// Token authentication
$client = new Gitlab\Client();
$client->authenticate('your_http_token', Gitlab\Client::AUTH_HTTP_TOKEN);

// OAuth2 authentication
$client = new Gitlab\Client();
$client->authenticate('your_oauth_token', Gitlab\Client::AUTH_OAUTH_TOKEN);

// An example API call
$project = $client->projects()->create('My Project', [
    'description' => 'This is a project',
    'issues_enabled' => false,
]);

自托管 GitLab

$client = new Gitlab\Client();
$client->setUrl('https://git.yourdomain.com');
$client->authenticate('your_http_token', Gitlab\Client::AUTH_HTTP_TOKEN);

带有分页器的示例

$pager = new Gitlab\ResultPager($client);
$issues = $pager->fetchAll($client->issues(), 'all', [null, ['state' => 'closed']]);

HTTP 客户端构建器

通过向 Gitlab\Client 构造函数提供一个 Gitlab\HttpClient\Builder,您可以自定义 HTTP 客户端。例如,要自定义用户代理

$plugin = new Http\Client\Common\Plugin\HeaderSetPlugin([
    'User-Agent' => 'Foobar',
]);

$builder = new Gitlab\HttpClient\Builder();
$builder->addPlugin($plugin);

$client = new Gitlab\Client($builder);

您可以在这里了解更多关于 HTTPlug 插件的信息。请查看API 方法,并且请随时报告任何错误,注意我们的行为准则

贡献

我们乐意接收问题报告并审查接受拉取请求,遵循我们的行为准则贡献指南

$ make install
$ make test

安全性

如果您在这个包中发现安全漏洞,请将邮件发送到 Graham Campbell 的 graham@alt-three.com 或 Miguel Piedrafita 的 github@miguelpiedrafita.com。所有安全漏洞都将得到及时处理。您可以在此查看我们的完整安全策略。

许可证

GitLab PHP API 客户端遵循MIT 许可证 (MIT)