aibnuhibban / bitbucket-laravel
A Laravel package to interact with Bitbucket API, focusing on repository creation.
Requires
- php: ^7.0|^8.0
- bitbucket/client: ^4.7
- guzzlehttp/guzzle: ^7.8
- http-interop/http-factory-guzzle: ^1.2
- illuminate/support: ^11.26
- symfony/process: ^7.1
This package is auto-updated.
Last update: 2025-03-20 06:03:25 UTC
README
Bitbucket Laravel is a Laravel package that integrates with the Bitbucket API to manage repositories, including creating new repositories within a workspace. This package is built on top of bitbucket/client and allows you to use the Bitbucket API in a Laravel-friendly way.
Installation
1. Install via Composer
You can install the package via Composer:
composer require aibnuhibban/bitbucket-laravel
2. Add the Service Provider
Add the service provider to the providers
array in config/app.php
:
'providers' => [
// Other service providers...
Aibnuhibban\BitbucketLaravel\Service\BitbucketLaravelServiceProvider::class,
],
3. Configure the API Token
Add your Bitbucket API Token to the .env
file:
BITBUCKET_TOKEN=your-bitbucket-api-token
Ensure the token has the appropriate permissions to access the workspace and create repositories.
Usage
Creating a New Repository
You can use the BitbucketService
to create a new repository in Bitbucket. Here's an example of how to use it in a Laravel controller:
use Aibnuhibban\BitbucketLaravel\Service\BitbucketService;
class BitbucketController extends Controller
{
protected $bitbucketService;
public function __construct(BitbucketService $bitbucketService)
{
$this->bitbucketService = $bitbucketService;
}
public function createRepo()
{
$workspace = 'your-workspace';
$repoName = 'new-repository';
$options = [
'is_private' => true,
'scm' => 'git', // SCM (Source Control Management), can be 'git' or 'hg'
'description' => 'Repository created via API',
];
$response = $this->bitbucketService->createRepository($workspace, $repoName, $options);
return response()->json($response);
}
}
Parameters for createRepository
$workspace
: The name of the workspace in Bitbucket.$repoName
: The name of the repository to be created.$options
: An array with the repository configurations such as:is_private
: Set the repository as private or public.scm
: The type of SCM, either'git'
or'hg'
.description
: A description for the repository.
Example Response
If the repository is created successfully, the API will return a JSON response with the details of the newly created repository.
{
"scm": "git",
"website": null,
"has_wiki": false,
"uuid": "{repository-uuid}",
"language": "",
"fork_policy": "no_public_forks",
"created_on": "2024-01-01T12:34:56.789Z",
...
}
Customization
If you need to extend the API functionality, you can easily do so by creating your own wrapper class or extending the service.
Testing
You can test the API functionality using Laravel's testing framework like PHPUnit or Pest.
Contributing
If you find any bugs or want to add new features, feel free to submit a pull request or open an issue.