Struct Api

Source
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

Source

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 repository
  • commit_id - The ID of the commit to get the build status for
  • repository_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(())
}

See the Bitbucket Data Center REST API documentation

Source§

impl Api

Source

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 repository
  • repository_slug - The slug of the repository
  • commit_id - The ID of the commit to post the build status for
  • build_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.

See Bitbucket Data Center REST API Docs

Source§

impl Api

Source

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 repository
  • repository_slug - The slug of the repository
  • pull_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(())
}

See the Bitbucket Data Center REST API documentation

Source§

impl Api

Source

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 repository
  • repository_slug - The slug of the repository
  • pull_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.

See Bitbucket Data Center REST API Docs

Auto Trait Implementations§

§

impl Freeze for Api

§

impl !RefUnwindSafe for Api

§

impl Send for Api

§

impl Sync for Api

§

impl Unpin for Api

§

impl !UnwindSafe for Api

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,