Skip to main content

subspace_contracts/issues/summary/
details.rs

1//! Optional details are boxed together so the existing resolution enum stays small.
2use super::{IssuePerson, IssueProgress, IssueSummary, LatestActivity, PullRequestSummary};
3#[derive(Clone, Default, PartialEq, Eq)]
4pub(super) struct Details {
5    pub priority: Option<u8>,
6    pub owner: Option<IssuePerson>,
7    pub assignee_id: Option<String>,
8    pub assignee_kind: Option<String>,
9    pub assignee_rank: Option<String>,
10    pub progress: Option<IssueProgress>,
11    pub pull_requests: Option<PullRequestSummary>,
12    pub due_date: Option<String>,
13    pub latest_activity: Option<LatestActivity>,
14    pub ready_for_agents: Option<bool>,
15}
16
17impl IssueSummary {
18    pub fn with_priority(mut self, value: Option<u8>) -> Self {
19        self.details.get_or_insert_with(Default::default).priority = value;
20        self
21    }
22    // qual:api - Consumed by app crates through the Framework facade.
23    pub fn priority(&self) -> Option<u8> {
24        self.details.as_ref().and_then(|facts| facts.priority)
25    }
26    pub fn with_owner(mut self, value: Option<IssuePerson>) -> Self {
27        self.details.get_or_insert_with(Default::default).owner = value;
28        self
29    }
30    pub fn owner(&self) -> Option<&IssuePerson> {
31        self.details.as_ref().and_then(|facts| facts.owner.as_ref())
32    }
33    /// Stable identity allows an owner comparison even when two people share a name.
34    // qual:api - Consumed by app crates through the Framework facade.
35    pub fn with_assignee_id(mut self, value: Option<&str>) -> Self {
36        self.details
37            .get_or_insert_with(Default::default)
38            .assignee_id = value.map(str::to_owned);
39        self
40    }
41    // qual:api - Consumed by app crates through the Framework facade.
42    pub fn assignee_id(&self) -> Option<&str> {
43        self.details
44            .as_ref()
45            .and_then(|facts| facts.assignee_id.as_deref())
46    }
47    pub fn with_assignee_kind(mut self, value: Option<&str>) -> Self {
48        self.details
49            .get_or_insert_with(Default::default)
50            .assignee_kind = value.map(str::to_owned);
51        self
52    }
53    // qual:api - Consumed by app crates through the Framework facade.
54    pub fn assignee_kind(&self) -> Option<&str> {
55        self.details
56            .as_ref()
57            .and_then(|facts| facts.assignee_kind.as_deref())
58    }
59    pub fn with_assignee_rank(mut self, value: Option<&str>) -> Self {
60        self.details
61            .get_or_insert_with(Default::default)
62            .assignee_rank = value.map(str::to_owned);
63        self
64    }
65    // qual:api - Consumed by app crates through the Framework facade.
66    pub fn assignee_rank(&self) -> Option<&str> {
67        self.details
68            .as_ref()
69            .and_then(|facts| facts.assignee_rank.as_deref())
70    }
71    pub fn with_progress(mut self, value: Option<IssueProgress>) -> Self {
72        self.details.get_or_insert_with(Default::default).progress = value;
73        self
74    }
75    pub fn progress(&self) -> Option<IssueProgress> {
76        self.details.as_ref().and_then(|facts| facts.progress)
77    }
78    pub fn with_pull_requests(mut self, value: Option<PullRequestSummary>) -> Self {
79        self.details
80            .get_or_insert_with(Default::default)
81            .pull_requests = value;
82        self
83    }
84    // qual:api - Consumed by app crates through the Framework facade.
85    pub fn pull_requests(&self) -> Option<&PullRequestSummary> {
86        self.details
87            .as_ref()
88            .and_then(|facts| facts.pull_requests.as_ref())
89    }
90    pub fn with_due_date(mut self, value: Option<&str>) -> Self {
91        self.details.get_or_insert_with(Default::default).due_date = value.map(str::to_owned);
92        self
93    }
94    // qual:api - Consumed by app crates through the Framework facade.
95    pub fn due_date(&self) -> Option<&str> {
96        self.details
97            .as_ref()
98            .and_then(|facts| facts.due_date.as_deref())
99    }
100    pub fn with_latest_activity(mut self, value: Option<LatestActivity>) -> Self {
101        self.details
102            .get_or_insert_with(Default::default)
103            .latest_activity = value;
104        self
105    }
106    // qual:api - Consumed by app crates through the Framework facade.
107    pub fn latest_activity(&self) -> Option<&LatestActivity> {
108        self.details
109            .as_ref()
110            .and_then(|facts| facts.latest_activity.as_ref())
111    }
112    /// Whether the issue is flagged Ready for agents, to be picked up by a
113    /// fleet's agents. `None` when the responder has not read it.
114    // qual:api - Consumed by app crates through the Framework facade.
115    pub fn with_ready_for_agents(mut self, value: Option<bool>) -> Self {
116        self.details
117            .get_or_insert_with(Default::default)
118            .ready_for_agents = value;
119        self
120    }
121    // qual:api - Consumed by app crates through the Framework facade.
122    pub fn ready_for_agents(&self) -> Option<bool> {
123        self.details
124            .as_ref()
125            .and_then(|facts| facts.ready_for_agents)
126    }
127}