承接 bitbucket/client 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

Banner

Build Status StyleCI Status Software License Packagist Downloads Latest Version

This is strongly based on php-github-api by KnpLabs. With this in mind, we now have very similar clients for:

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 bitbucket/client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 831.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 103
  • 点击次数: 37
  • 依赖项目数: 12
  • 推荐数: 0

GitHub 信息

  • Stars: 102
  • Watchers: 3
  • Forks: 26
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-31