Skip to main content

azure_devops/builds/methods/
get_latest.rs

1use super::super::models::Build;
2use super::super::BuildsClient;
3use crate::constants;
4use crate::constants::ApiPath;
5use crate::error::Result;
6
7impl BuildsClient<'_> {
8    /// Get the latest build for a definition, optionally filtered by branch.
9    ///
10    /// # Arguments
11    ///
12    /// * `project` — The project name.
13    /// * `def` — The build definition ID.
14    /// * `branch` — Optional branch name filter.
15    ///
16    /// # Returns
17    ///
18    /// The latest [`Build`] matching the criteria.
19    pub async fn get_latest(&self, project: &str, def: i64, branch: Option<&str>) -> Result<Build> {
20        let qp = branch.map_or_else(Vec::new, |b| {
21            vec![(constants::query::BRANCH_NAME.into(), b.into())]
22        });
23        self.http
24            .get(
25                &ApiPath::build_latest(project, def),
26                &crate::util::ref_query(&qp),
27            )
28            .await
29    }
30}