bitbucket-server-rs
A Rust client library for interacting with the Bitbucket Data Center REST API. This library provides a type-safe, ergonomic interface for Bitbucket Server (on-premise Bitbucket Data Center) operations, making it ideal for automation tools, CI/CD integrations, and Rust applications that need to interact with Bitbucket.
Features
- Type-safe API: Strongly typed interfaces for Bitbucket Server REST API endpoints
- Async/Await Support: Built on tokio and reqwest for modern asynchronous workflows
- Error Handling: Comprehensive error types for better error management
- Builder Pattern: Fluent API design for constructing requests
- JSON Serialization/Deserialization: Automatic handling of JSON payloads
- Authentication: Bearer token authentication support
Currently Supported APIs
- Build Status: Get and post build statuses for commits
- Pull Request Changes: Retrieve changes in pull requests
Installation
Add this to your Cargo.toml:
[]
= "0.3.1"
= { = "1.0", = ["full"] } # For async runtime
Usage
Creating a Client
use new;
// Create a new client with base URL and API token
let client = new;
Getting Build Status
use ;
use BuildStatus;
async
Posting Build Status
use new;
use BuildStatusState;
async
Getting Pull Request Changes
use new;
async
Error Handling
The library provides a comprehensive error type ApiError that covers various failure scenarios:
Example of error handling:
match client.api.build_status_get.build?.send.await
Custom HTTP Client Configuration
You can customize the HTTP client configuration:
use ;
use ClientBuilder;
// Create a custom HTTP client
let http_client = new
.timeout
.build
.expect;
// Create a new Bitbucket client
let mut client = new;
// Set the custom HTTP client
client.with_http_client;
CI/CD
This project uses GitHub Actions for continuous integration and deployment:
- PR Check: Runs tests and ensures version is bumped on pull requests
- Publish: Automatically publishes to crates.io when changes are merged to main
Setting up for Publishing
To enable publishing to crates.io with manual approval, you need to:
- Generate a new token on crates.io
- Go to your GitHub repository settings → Secrets and variables → Actions
- Add a new repository secret named
CRATES_IO_TOKENwith your crates.io API token as the value - Go to Settings → Environments → New environment
- Create an environment named
crates-io-publish - Add required reviewers who must approve the publishing step
With this setup, the workflow will:
- Automatically prepare the release when changes are merged to main
- Run build and tests to verify everything works
- Wait for manual approval from the required reviewers
- After approval, publish to crates.io, which triggers docs.rs to build and publish the documentation
You can also manually trigger the publishing workflow from the Actions tab in GitHub.
Contributing
Contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature-name - Submit a pull request
Please make sure to update tests as appropriate and follow the Rust code style guidelines.
Version Bumping
When making changes, remember to bump the version in Cargo.toml according to Semantic Versioning principles:
- MAJOR version for incompatible API changes
- MINOR version for adding functionality in a backwards compatible manner
- PATCH version for backwards compatible bug fixes
The CI workflow will verify that the version has been bumped in pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.