use std::fmt::{Display, Formatter};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use url::Url;
use crate::id;
use crate::resource::{
App, CheckRunConclusion, CheckRunStatus, GitRef, GitSha, NodeId, PullRequest,
};
pub use self::minimal::MinimalCheckSuite;
mod minimal;
id!(
CheckSuiteId
);
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct CheckSuite {
#[serde(flatten)]
minimal: MinimalCheckSuite,
node_id: NodeId,
head_branch: GitRef,
head_sha: GitSha,
status: CheckRunStatus,
conclusion: Option<CheckRunConclusion>,
url: Url,
before: GitSha,
after: GitSha,
pull_requests: Vec<PullRequest>,
app: App,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
}
impl CheckSuite {
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn id(&self) -> CheckSuiteId {
self.minimal.id()
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn node_id(&self) -> &NodeId {
&self.node_id
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn head_branch(&self) -> &GitRef {
&self.head_branch
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn head_sha(&self) -> &GitSha {
&self.head_sha
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn status(&self) -> CheckRunStatus {
self.status
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn conclusion(&self) -> Option<CheckRunConclusion> {
self.conclusion
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn url(&self) -> &Url {
&self.url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn before(&self) -> &GitSha {
&self.before
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn after(&self) -> &GitSha {
&self.after
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn pull_requests(&self) -> &Vec<PullRequest> {
&self.pull_requests
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn app(&self) -> &App {
&self.app
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn created_at(&self) -> &DateTime<Utc> {
&self.created_at
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn updated_at(&self) -> &DateTime<Utc> {
&self.updated_at
}
}
impl Display for CheckSuite {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.id())
}
}
#[cfg(test)]
mod tests {
use super::CheckSuite;
#[test]
fn trait_deserialize() {
let suite: CheckSuite = serde_json::from_str(include_str!(
"../../../tests/fixtures/resource/check_suite.json"
))
.unwrap();
assert_eq!(7663255123, suite.id().get());
}
#[test]
fn trait_display() {
let suite: CheckSuite = serde_json::from_str(include_str!(
"../../../tests/fixtures/resource/check_suite.json"
))
.unwrap();
assert_eq!("7663255123", suite.to_string());
}
#[test]
fn trait_send() {
fn assert_send<T: Send>() {}
assert_send::<CheckSuite>();
}
#[test]
fn trait_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<CheckSuite>();
}
}