1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! # Bitbucket Server Rust Client
//!
//! `bitbucket-server-rs` is 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
//!
//! ## Usage
//!
//! ### Creating a Client
//!
//! ```no_run
//! use bitbucket_server_rs::client::new;
//!
//! // Create a new client with base URL and API token
//! let client = new(
//! "https://bitbucket-server/rest",
//! "YOUR_API_TOKEN"
//! );
//! ```
//!
//! ### Getting Build Status
//!
//! ```no_run
//! use bitbucket_server_rs::client::{new, ApiRequest};
//! use bitbucket_server_rs::api::build_status_get::BuildStatus;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = new(
//! "https://bitbucket-server/rest",
//! "YOUR_API_TOKEN"
//! );
//!
//! // Get build status for a specific commit
//! let response = client
//! .api()
//! .build_status_get(
//! "PROJECT_KEY",
//! "COMMIT_ID",
//! "REPOSITORY_SLUG"
//! )
//! .key("build-123") // Optional: filter by build key
//! .build()?
//! .send()
//! .await?;
//!
//! // Handle the response
//! match response {
//! Some(build_status) => {
//! println!("Build state: {:?}", build_status.state);
//! println!("Build URL: {}", build_status.url);
//! // Access other fields as needed
//! },
//! None => println!("No build status found")
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Posting Build Status
//!
//! ```no_run
//! use bitbucket_server_rs::client::{new, ApiRequest};
//! use bitbucket_server_rs::api::build_status::{BuildStatusState, TestResults};
//! use bitbucket_server_rs::api::build_status_post::BuildStatusPostPayload;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = new(
//! "https://bitbucket-server/rest",
//! "YOUR_API_TOKEN"
//! );
//!
//! // Create build status payload
//! let build_status = BuildStatusPostPayload {
//! key: "build-123".to_string(),
//! state: BuildStatusState::Successful,
//! url: "https://ci.example.com/build/123".to_string(),
//! description: Some("Build passed successfully".to_string()),
//! name: Some("CI Build".to_string()),
//! ..Default::default()
//! };
//!
//! // Post a build status for a commit
//! let response = client
//! .api()
//! .build_status_post(
//! "PROJECT_KEY",
//! "REPOSITORY_SLUG",
//! "COMMIT_ID",
//! &build_status
//! )
//! .send()
//! .await?;
//!
//! println!("Build status posted successfully");
//!
//! Ok(())
//! }
//! ```
//!
//! ### Getting Pull Request Changes
//!
//! ```no_run
//! use bitbucket_server_rs::client::{new, ApiRequest};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = new(
//! "https://bitbucket-server/rest",
//! "YOUR_API_TOKEN"
//! );
//!
//! // Get changes for a pull request
//! let response = client
//! .api()
//! .pull_request_changes_get(
//! "PROJECT_KEY",
//! "REPOSITORY_SLUG",
//! "123" // Pull request ID
//! )
//! .start(0u32)
//! .limit(100u32)
//! .build()?
//! .send()
//! .await?;
//!
//! // Handle the response
//! if let Some(changes) = response {
//! println!("Changes found!");
//! // Process changes
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## Error Handling
//!
//! The library provides a comprehensive error type `ApiError` that covers various failure scenarios:
//!
//! ```no_run
//! use bitbucket_server_rs::client::{new, ApiError, ApiRequest};
//!
//! #[tokio::main]
//! async fn main() {
//! let client = new("https://bitbucket-server/rest", "API_TOKEN");
//!
//! match client.api().build_status_get("PROJECT", "COMMIT", "REPO").build().unwrap().send().await {
//! Ok(response) => {
//! // Handle successful response
//! },
//! Err(ApiError::Unauthorized) => {
//! eprintln!("Authentication failed. Check your API token.");
//! },
//! Err(ApiError::HttpClientError(status, message)) => {
//! eprintln!("Client error ({}): {}", status, message);
//! },
//! Err(e) => {
//! eprintln!("Request failed: {:?}", e);
//! }
//! }
//! }
//! ```
/// Bitbucket's `api` API module containing all API endpoint implementations
/// REST API Client module providing the core client functionality