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 Nov 26, 2023
1 parent 551871a commit fec92a1
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 @@ -20,6 +20,33 @@ pub enum CheckRunStatus {
Completed,
}

#[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 @@ -73,6 +100,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 @@ -188,6 +216,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 @@ -198,6 +230,8 @@ impl<'octo, 'r> ListCheckRunsInCheckSuiteBuilder<'octo, 'r> {
Self {
handler,
check_suite_id,
check_name: None,
status: None,
per_page: None,
page: None,
}
Expand All @@ -215,6 +249,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 @@ -352,4 +398,18 @@ impl<'octo> ChecksHandler<'octo> {
pub fn update_check_run(&self, check_run_id: CheckRunId) -> UpdateCheckRunBuilder<'_, '_> {
UpdateCheckRunBuilder::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)
}
}
2 changes: 2 additions & 0 deletions src/models/checks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use crate::models::pulls::PullRequest;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
Expand All @@ -13,6 +14,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 fec92a1

Please sign in to comment.