#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum PullRequestStatus {
Open,
Draft,
Merged,
Closed,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ReviewStatus {
Approved,
ChangesRequested,
ReviewRequired,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum CheckStatus {
Success,
Failure,
Pending,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct CheckCounts {
pub passed: u32,
pub total: u32,
}
impl CheckCounts {
pub fn new(passed: u32, total: u32) -> Self {
Self {
passed: passed.min(total),
total,
}
}
}
#[derive(Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct PullRequestDetails {
pub key: String,
pub title: String,
pub url: String,
pub status: PullRequestStatus,
pub author: Option<String>,
pub review: Option<ReviewStatus>,
pub checks: Option<CheckStatus>,
pub check_counts: Option<CheckCounts>,
pub updated_at: Option<String>,
pub head_ref: Option<String>,
pub base_ref: Option<String>,
pub additions: Option<u32>,
pub deletions: Option<u32>,
}
impl PullRequestDetails {
pub fn new(key: &str, title: &str, url: &str, status: PullRequestStatus) -> Self {
Self {
key: key.into(),
title: title.into(),
url: url.into(),
status,
author: None,
review: None,
checks: None,
check_counts: None,
updated_at: None,
head_ref: None,
base_ref: None,
additions: None,
deletions: None,
}
}
pub fn with_author(mut self, author: Option<&str>) -> Self {
self.author = author.map(str::to_owned);
self
}
pub fn with_review(mut self, review: Option<ReviewStatus>) -> Self {
self.review = review;
self
}
pub fn with_checks(mut self, checks: Option<CheckStatus>) -> Self {
self.checks = checks;
self
}
pub fn with_check_counts(mut self, counts: Option<CheckCounts>) -> Self {
self.check_counts = counts;
self
}
pub fn with_updated_at(mut self, updated_at: Option<&str>) -> Self {
self.updated_at = updated_at.map(str::to_owned);
self
}
pub fn with_branches(mut self, head: Option<&str>, base: Option<&str>) -> Self {
self.head_ref = head.map(str::to_owned);
self.base_ref = base.map(str::to_owned);
self
}
pub fn with_changes(mut self, additions: Option<u32>, deletions: Option<u32>) -> Self {
self.additions = additions;
self.deletions = deletions;
self
}
}