emri99/gitlab-generic-api-client
Composer 安装命令:
composer require emri99/gitlab-generic-api-client
包简介
PHP GitLab generic API client (not stick to any version)
README 文档
README
This library has been built keeping in mind that Gitlab move so fast, that it becomes hard to apply changes and migration guides on complex code base.
How it works
This code is inpired by npm package gitlab-api-client.
Next lines descriptions too.
Main principle: All paths are build generically.
You aren't stick to any specific API version as you will have access to
all the gitlab API endpoints, even for those that haven't been defined yet.
Installation
composer require emri99/gitlab-generic-api-client
Usage
Authentication
- Authenticate using HTTP token
$client->authenticate('SECRET-HTTP-TOKEN', GitlabApiClient::AUTH_HTTP_TOKEN);
- Authenticate using OAUTH token
$client->authenticate('SECRET-OAUTH-TOKEN', GitlabApiClient::AUTH_OAUTH_TOKEN);
Requesting
- GET request
$client = new GitlabApiClient('https://my.gitlab.com/api/v4'); $branches = $client->projects(1) ->repository() ->branches() ->get() // will send GET request on // https://my.gitlab.com/api/v4/projects/1/repository/branches. foreach($branches as $branch) { echo $branch->name, "\n"; }
- POST request
# create a variable secret $variableDatas = $this->getClient() ->projects(2) ->variables() ->post([ 'key' => 'SECRET', 'value' => 'password' ]);
- PUT request
# protect a branch $branchUpdated = $this->getClient() ->projects(2) ->repository() ->branches('master') ->protect()->put([ 'developers_can_push' => false, 'developers_can_merge' => false ]); $done = $branchUpdated->protected;
- DELETE request
# delete a branch $branchUpdated = $this->getClient() ->projects(2) ->repository() ->branches('obsolet-feature') ->delete();
Special case
If an url segment is the same than a public method of GitlabApiClient, this
remains possible to build to path correctly.
For example, to build path user/1/delete, use:
$client->user(1, 'delete');
IDE Completion depending on gitlab api version (optional)
Empty classes can be used to simulate code completion on retrieved object
by installing emri99/gitlab-generic-api-client-models.
This optional package is tagged by gitlab API version.
Currently there isn't many versions handled, only the one I'm using. ie: 9.1.4
When using this package, retrieved objects WONT BE instance of models class.
Retrieved objects remainsstdclass. This is ONLY used for IDE completion.
composer require emri99/gitlab-generic-api-client-models:YOUR_GITLAB_VERSION --dev
YOU MUST add phpdoc to use completion like below:
- GET
$client = new GitlabApiClient('https://my.gitlab.com/api/v4'); /** * $branches aint really a Branch instance * @var Branch[] $branches */ $branches = $client->projects(1) ->repository() ->branches() ->get(array( // parameters )) // $branches is an array of stdclass having // the same properties than a Branch class foreach($branches as $branch) { echo $branch->name; }
Contributing
Thanks for contributing !
Please follow this rules:
- you MUST apply supplied CS-fixer by running
composer run-script cs - you MUST write/update the tests
- you SHOULD write documentation
- you MUST write minimum details in pull request description
Squashing many commits to avoid noise on git logs make sense too ;)
emri99/gitlab-generic-api-client 适用场景与选型建议
emri99/gitlab-generic-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.09k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「gitlab」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 emri99/gitlab-generic-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 emri99/gitlab-generic-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 emri99/gitlab-generic-api-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A collection of monolog handlers using PSR-18 http client
A PSR-7 compatible library for making CRUD API endpoints
Creates & updates issues on a GitLab repository from Symfony2 exceptions
Library to handle Webhooks from various services.
A PSR-15 middleware to manage Gitlab hooks.
In-app feedback and bug reporting for Laravel: a floating button that turns client reports with annotated screenshots into GitHub or GitLab issues.
统计信息
- 总下载量: 10.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-27