subspace_contracts/github/
details.rs1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6#[non_exhaustive]
7pub enum PullRequestStatus {
8 Open,
9 Draft,
10 Merged,
11 Closed,
12}
13
14#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16#[non_exhaustive]
17pub enum ReviewStatus {
18 Approved,
19 ChangesRequested,
20 ReviewRequired,
21}
22
23#[derive(Clone, Copy, Debug, PartialEq, Eq)]
25#[non_exhaustive]
26pub enum CheckStatus {
27 Success,
28 Failure,
29 Pending,
30}
31
32#[derive(Clone, Copy, Debug, PartialEq, Eq)]
35#[non_exhaustive]
36pub struct CheckCounts {
37 pub passed: u32,
38 pub total: u32,
39}
40
41impl CheckCounts {
42 pub fn new(passed: u32, total: u32) -> Self {
43 Self {
44 passed: passed.min(total),
45 total,
46 }
47 }
48}
49
50#[derive(Clone, PartialEq, Eq)]
52#[non_exhaustive]
53pub struct PullRequestDetails {
54 pub key: String,
56 pub title: String,
57 pub url: String,
59 pub status: PullRequestStatus,
60 pub author: Option<String>,
62 pub review: Option<ReviewStatus>,
63 pub checks: Option<CheckStatus>,
64 pub check_counts: Option<CheckCounts>,
67 pub updated_at: Option<String>,
69 pub head_ref: Option<String>,
70 pub base_ref: Option<String>,
71 pub additions: Option<u32>,
72 pub deletions: Option<u32>,
73}
74
75impl PullRequestDetails {
77 pub fn new(key: &str, title: &str, url: &str, status: PullRequestStatus) -> Self {
78 Self {
79 key: key.into(),
80 title: title.into(),
81 url: url.into(),
82 status,
83 author: None,
84 review: None,
85 checks: None,
86 check_counts: None,
87 updated_at: None,
88 head_ref: None,
89 base_ref: None,
90 additions: None,
91 deletions: None,
92 }
93 }
94
95 pub fn with_author(mut self, author: Option<&str>) -> Self {
97 self.author = author.map(str::to_owned);
98 self
99 }
100
101 pub fn with_review(mut self, review: Option<ReviewStatus>) -> Self {
103 self.review = review;
104 self
105 }
106
107 pub fn with_checks(mut self, checks: Option<CheckStatus>) -> Self {
108 self.checks = checks;
109 self
110 }
111
112 pub fn with_check_counts(mut self, counts: Option<CheckCounts>) -> Self {
115 self.check_counts = counts;
116 self
117 }
118
119 pub fn with_updated_at(mut self, updated_at: Option<&str>) -> Self {
121 self.updated_at = updated_at.map(str::to_owned);
122 self
123 }
124
125 pub fn with_branches(mut self, head: Option<&str>, base: Option<&str>) -> Self {
128 self.head_ref = head.map(str::to_owned);
129 self.base_ref = base.map(str::to_owned);
130 self
131 }
132
133 pub fn with_changes(mut self, additions: Option<u32>, deletions: Option<u32>) -> Self {
136 self.additions = additions;
137 self.deletions = deletions;
138 self
139 }
140}