Skip to content

Commit

Permalink
feat: add check run pull requests and list parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Apr 19, 2024
1 parent 7e280be commit 022246f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/api/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<models::checks::CheckRun> {
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)]
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
status: Option<CheckRunStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
per_page: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
page: Option<u32>,
Expand All @@ -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,
}
Expand All @@ -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<String>) -> 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<models::checks::ListCheckRuns> {
let route = format!(
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 2 additions & 0 deletions src/models/checks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::models::workflows::HeadCommit;

use super::*;
use crate::models::pulls::PullRequest;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
Expand All @@ -26,6 +27,7 @@ pub struct CheckRun {
pub started_at: Option<chrono::DateTime<chrono::Utc>>,
pub completed_at: Option<chrono::DateTime<chrono::Utc>>,
pub name: String,
pub pull_requests: Vec<PullRequest>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down

0 comments on commit 022246f

Please sign in to comment.