diff --git a/src/api/checks.rs b/src/api/checks.rs index 79d95d2b..805f39a8 100644 --- a/src/api/checks.rs +++ b/src/api/checks.rs @@ -17,6 +17,33 @@ pub struct ChecksHandler<'octo> { repo: String, } +#[derive(serde::Serialize)] +pub struct GetCheckRunBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r ChecksHandler<'octo>, + check_run_id: CheckRunId, +} + +impl<'octo, 'r> GetCheckRunBuilder<'octo, 'r> { + pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_run_id: CheckRunId) -> Self { + Self { + handler, + check_run_id, + } + } + + pub async fn send(self) -> Result { + let route = format!( + "/repos/{owner}/{repo}/check-runs/{check_run_id}", + owner = self.handler.owner, + repo = self.handler.repo, + check_run_id = self.check_run_id + ); + + self.handler.crab.get(route, None::<&()>).await + } +} + #[derive(serde::Serialize)] pub struct CreateCheckRunBuilder<'octo, 'r> { #[serde(skip)] @@ -99,6 +126,7 @@ impl<'octo, 'r> CreateCheckRunBuilder<'octo, 'r> { owner = self.handler.owner, repo = self.handler.repo ); + self.handler.crab.post(route, Some(&self)).await } } @@ -212,6 +240,10 @@ pub struct ListCheckRunsInCheckSuiteBuilder<'octo, 'r> { handler: &'r ChecksHandler<'octo>, check_suite_id: CheckSuiteId, #[serde(skip_serializing_if = "Option::is_none")] + check_name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + status: Option, + #[serde(skip_serializing_if = "Option::is_none")] per_page: Option, #[serde(skip_serializing_if = "Option::is_none")] page: Option, @@ -222,6 +254,8 @@ impl<'octo, 'r> ListCheckRunsInCheckSuiteBuilder<'octo, 'r> { Self { handler, check_suite_id, + check_name: None, + status: None, per_page: None, page: None, } @@ -239,6 +273,18 @@ impl<'octo, 'r> ListCheckRunsInCheckSuiteBuilder<'octo, 'r> { self } + /// Returns check runs with the specified `name`. + pub fn check_name(mut self, check_name: impl Into) -> Self { + self.check_name = Some(check_name.into()); + self + } + + /// Returns check runs with the specified `status`. + pub fn status(mut self, status: CheckRunStatus) -> Self { + self.status = Some(status); + self + } + /// Send the actual request. pub async fn send(self) -> Result { let route = format!( @@ -582,6 +628,20 @@ impl<'octo> ChecksHandler<'octo> { ) -> crate::api::checks::CheckRunAnnotationsBuilder<'_, '_> { CheckRunAnnotationsBuilder::new(self, check_run_id) } + + /// ```no_run + /// # async fn run() -> octocrab::Result<()> { + /// let check_run = octocrab::instance() + /// .checks("owner", "repo") + /// .get_check_run(123456.into()) + /// .send() + /// .await?; + /// # Ok(()) + /// # } + /// ``` + pub fn get_check_run(&self, check_run_id: CheckRunId) -> GetCheckRunBuilder<'_, '_> { + GetCheckRunBuilder::new(self, check_run_id) + } } #[derive(serde::Serialize)] diff --git a/src/models/checks.rs b/src/models/checks.rs index 3f737e01..63349437 100644 --- a/src/models/checks.rs +++ b/src/models/checks.rs @@ -1,6 +1,7 @@ use crate::models::workflows::HeadCommit; use super::*; +use crate::models::pulls::PullRequest; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] @@ -26,6 +27,7 @@ pub struct CheckRun { pub started_at: Option>, pub completed_at: Option>, pub name: String, + pub pull_requests: Vec, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]