pub struct Api {
pub client: Client,
}
Expand description
Bitbucket’s api
API. i.e. https://bitbucket-server/rest/api
This struct serves as the entry point for all API operations. It holds a reference to the HTTP client that will be used for making requests.
Fields§
§client: Client
The http client to use for making requests. This includes the base URL, the HTTP client, and the API token.
Implementations§
Source§impl Api
impl Api
Sourcepub fn build_status_get(
&self,
project_key: &str,
commit_id: &str,
repository_slug: &str,
) -> BuildStatusGetBuilder
pub fn build_status_get( &self, project_key: &str, commit_id: &str, repository_slug: &str, ) -> BuildStatusGetBuilder
Creates a request builder for retrieving build status information.
This method returns a builder that can be used to configure and send a request to retrieve build status information for a commit.
§Arguments
project_key
- The key of the project containing the repositorycommit_id
- The ID of the commit to get the build status forrepository_slug
- The slug of the repository
§Returns
A builder for configuring and sending the request
§Example
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", "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);
},
None => println!("No build status found")
}
Ok(())
}
Source§impl Api
impl Api
Sourcepub fn build_status_post(
self,
project_key: &str,
repository_slug: &str,
commit_id: &str,
build_status: &BuildStatusPostPayload,
) -> BuildStatusPost
pub fn build_status_post( self, project_key: &str, repository_slug: &str, commit_id: &str, build_status: &BuildStatusPostPayload, ) -> BuildStatusPost
Creates a request to post a build status update for a commit.
This method returns a builder that can be used to send a request to post a build status update for a commit.
§Arguments
project_key
- The key of the project containing the repositoryrepository_slug
- The slug of the repositorycommit_id
- The ID of the commit to post the build status forbuild_status
- The build status payload to post
§Returns
A builder for sending the request
§Example
use bitbucket_server_rs::client::{new, ApiRequest};
use bitbucket_server_rs::api::build_status::BuildStatusState;
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", "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 the build status
let response = client
.api()
.build_status_post(
"PROJECT_KEY",
"REPOSITORY_SLUG",
"COMMIT_ID",
&build_status
)
.send()
.await?;
println!("Build status posted successfully");
Ok(())
}
§Notes
- The authenticated user must have REPO_READ permission for the repository that this build status is for. The request can also be made with anonymous 2-legged OAuth.
Source§impl Api
impl Api
Sourcepub fn pull_request_changes_get(
self,
project_key: &str,
repository_slug: &str,
pull_request_id: &str,
) -> PullRequestChangesGetBuilder
pub fn pull_request_changes_get( self, project_key: &str, repository_slug: &str, pull_request_id: &str, ) -> PullRequestChangesGetBuilder
Creates a request builder for retrieving changes in a pull request.
This method returns a builder that can be used to configure and send a request to retrieve the changes in a pull request.
§Arguments
project_key
- The key of the project containing the repositoryrepository_slug
- The slug of the repositorypull_request_id
- The ID of the pull request
§Returns
A builder for configuring and sending the request
§Example
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", "API_TOKEN");
let response = client
.api()
.pull_request_changes_get("PROJECT", "REPO", "123")
.limit(50u32)
.build()?
.send()
.await?;
Ok(())
}
Source§impl Api
impl Api
Sourcepub fn pull_request_post(
self,
project_key: &str,
repository_slug: &str,
pull_request: &PullRequestPostPayload,
) -> PullRequestPost
pub fn pull_request_post( self, project_key: &str, repository_slug: &str, pull_request: &PullRequestPostPayload, ) -> PullRequestPost
Creates a request to create a new pull request.
This method returns a builder that can be used to send a request to create a new pull request.
§Arguments
project_key
- The key of the project containing the repositoryrepository_slug
- The slug of the repositorypull_request
- The pull request payload
§Returns
A builder for sending the request
§Example
use bitbucket_server_rs::client::{new, ApiRequest};
use bitbucket_server_rs::api::pull_request_post::{
PullRequestPostPayload, RefInfo, RepositoryInfo, ProjectInfo
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = new("https://bitbucket-server/rest", "API_TOKEN");
// Create pull request payload
let pull_request = PullRequestPostPayload {
title: "Add new feature".to_string(),
description: Some("Implements the new feature".to_string()),
from_ref: RefInfo {
id: "refs/heads/feature-branch".to_string(),
repository: RepositoryInfo {
slug: "my-repo".to_string(),
project: ProjectInfo {
key: "PROJECT".to_string(),
},
},
},
to_ref: RefInfo {
id: "refs/heads/main".to_string(),
repository: RepositoryInfo {
slug: "my-repo".to_string(),
project: ProjectInfo {
key: "PROJECT".to_string(),
},
},
},
reviewers: None,
};
// Create the pull request
let response = client
.api()
.pull_request_post(
"PROJECT",
"my-repo",
&pull_request
)
.send()
.await?;
println!("Pull request created successfully");
Ok(())
}
§Notes
- The authenticated user must have REPO_WRITE permission for the repository to create pull requests.