bitbucket/client
Composer 安装命令:
composer require bitbucket/client
包简介
Bitbucket API 2.0 client for PHP
关键字:
README 文档
README
We present a modern Bitbucket API 2.0 client for PHP.
This is strongly based on php-github-api by KnpLabs. With this in mind, we now have very similar clients for:
- GitHub - knplabs/github-api by KnpLabs.
- GitLab - m4tthumphrey/php-gitlab-api by Matt Humphrey et al.
- Bitbucket - bitbucket/client which is this package!
Check out the change log, releases, security policy, license, code of conduct, and contribution guidelines.
Installation
This version supports PHP 8.1-8.5. To get started, simply require the project using Composer. You will also need to install packages that "provide" psr/http-client-implementation and psr/http-factory-implementation.
Standard Installation
$ composer require "bitbucket/client:^5.1" "guzzlehttp/guzzle:^7.9.2"
Framework Integration
Laravel:
$ composer require "graham-campbell/bitbucket:^11.1"
We are decoupled from any HTTP messaging client by using PSR-7, PSR-17, PSR-18, and HTTPlug. You can visit HTTPlug for library users to get more information about installing HTTPlug related packages. The framework integration graham-campbell/bitbucket is by Graham Campbell.
Usage
The main point of entry is the Bitbucket\Client class. Simply create a new instance of that, authenticate, and you're good to go! This client exposes Bitbucket API 2.0 endpoints through fluent resource classes. We'd recommend looking through the Bitbucket documentation, and also the source code to get a full picture of what is available to use.
Authentication
There are three ways to authenticate our client:
OAuth 2 Token
The most common way to authenticate is using an OAuth 2 token. You will need to generate this by some means outside of the library, and then provide it as below:
$client = new Bitbucket\Client(); $client->authenticate( Bitbucket\Client::AUTH_OAUTH_TOKEN, 'your-token-here' );
HTTP Basic
It is possible to authenticate using HTTP Basic credentials. For Bitbucket API tokens, use your Atlassian account email as the username and the API token as the password:
$client = new Bitbucket\Client(); $client->authenticate( Bitbucket\Client::AUTH_HTTP_PASSWORD, 'your-email@example.com', 'your-api-token-here' );
Bitbucket API tokens are the long-term replacement for app passwords, which Bitbucket has deprecated. Do not use your Atlassian account password here.
JSON Web Token
Finally, we support logging in using JSON web tokens (JWTs). This method is required by some Bitbucket API endpoints, such as the addons API. Generate your JWT, perhaps using lcobucci/jwt, then provide it as below:
$client = new Bitbucket\Client(); $client->authenticate( Bitbucket\Client::AUTH_JWT, 'your-jwt-here' );
Examples
In the following examples, $client will be an authenticated client, as above.
Example 1
It is possible to show basic information about the currently logged in user:
$currentUser = $client->currentUser()->show();
Example 2
It is possible to grab a repository as follows:
$repository = $client->repositories() ->workspaces('atlassian') ->show('stash-example-plugin');
Example 3
We support automatic pagination without you having to lift a finger. The following example gets all branches of a repository:
$paginator = new Bitbucket\ResultPager($client); $branchesClient = $client->repositories() ->workspaces('atlassianlabs') ->refs('stash-log-parser') ->branches(); $branches = $paginator->fetchAll($branchesClient, 'list');
Filtering and sorting parameters can be passed through the third argument to fetchAll():
$paginator = new Bitbucket\ResultPager($client); $tagsClient = $client->repositories() ->workspaces('my-workspace') ->refs('my-repo') ->tags(); $tags = $paginator->fetchAll($tagsClient, 'list', [['q' => 'name ~ "v1"', 'sort' => '-name']]);
Bitbucket includes those query parameters in the next pagination URL, so subsequent pages preserve them automatically.
To list files from a specific branch or commit, use the source API with ResultPager. Directory listings include both commit_file and commit_directory entries, so filter the returned values by type if you only need files:
$paginator = new Bitbucket\ResultPager($client); $srcClient = $client->repositories() ->workspaces('my-workspace') ->src('my-repo'); $entries = $paginator->fetchAll($srcClient, 'show', ['main', '/', ['max_depth' => 10]]);
Migrating Deprecated Bitbucket Endpoints
Bitbucket is removing or deprecating several cross-workspace endpoints. This client keeps the older methods available in v5.1, but marks them as deprecated where Bitbucket has published a supported replacement or removal notice.
| Deprecated usage | Replacement |
|---|---|
$client->currentUser()->listWorkspaces() |
$client->currentUser()->workspaces()->list() |
$client->currentUser()->listWorkspacePermissions() |
$client->currentUser()->workspaces()->permissions($workspace)->show() |
$client->currentUser()->listRepositoryPermissions() |
$client->currentUser()->workspaces()->permissions($workspace)->repositories()->list() |
$client->currentUser()->listTeamPermissions() |
Workspace APIs, where applicable |
$client->pullRequests()->list($selectedUser) |
$client->workspaces($workspace)->pullRequests()->list($selectedUser) |
$client->repositories()->list() |
$client->repositories()->workspaces($workspace)->list() |
$client->users($user)->repositories()->list() |
$client->repositories()->workspaces($workspace)->list() |
$client->snippets()->list() |
$client->snippets()->workspaces($workspace)->list() |
The replacement endpoints are usually workspace-scoped. If your application previously relied on cross-workspace results, enumerate the current user's workspaces and aggregate the workspace-scoped results in your application code.
$paginator = new Bitbucket\ResultPager($client); foreach ($paginator->fetchAll($client->currentUser()->workspaces(), 'list') as $workspaceAccess) { $workspace = $workspaceAccess['workspace']['slug']; $permissions = $paginator->fetchAll( $client->currentUser()->workspaces()->permissions($workspace)->repositories(), 'list' ); }
The supported current user workspaces endpoint returns workspace_access values, not the old workspace object shape. The workspace details are available under the workspace key on each result.
Contributing
We will gladly receive issue reports and review and accept pull requests, in accordance with our code of conduct and contribution guidelines!
$ make install
$ make test
Security
If you discover a security vulnerability within this package, please send an email to Graham Campbell at hello@gjcampbell.co.uk. All security vulnerabilities will be promptly addressed. You may view our full security policy here.
License
Bitbucket PHP API Client is licensed under The MIT License (MIT).
For Enterprise
Available as part of the Tidelift Subscription
The maintainers of bitbucket/client and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
bitbucket/client 适用场景与选型建议
bitbucket/client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 831.1k 次下载、GitHub Stars 达 102, 最近一次更新时间为 2018 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bitbucket」 「Graham Campbell」 「GrahamCampbell」 「Bitbucket API」 「BitbucketAPI」 「Bitbucket Client」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bitbucket/client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bitbucket/client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bitbucket/client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
MediaWiki extension that allows embedding external content, specified by URL, into your wiki pages
Provider-agnostic code review guardian for PHP projects. Works with any PHP project (Symfony, Laravel, Yii, CodeIgniter, etc.) and any Git provider (GitHub, GitLab, Bitbucket, etc.)
GitHub Is A GitHub Bridge For Laravel 5
Social Connection Auth Component
Flysystem Is A Flysystem Bridge For Laravel 5
Flysystem Is A Flysystem Bridge For Laravel 5
统计信息
- 总下载量: 831.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 103
- 点击次数: 37
- 依赖项目数: 12
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-31
