| 1 | use super::RepositoryResult; |
| 2 | use crate::domain::{ |
| 3 | IssueNumber, PullRequest, PullRequestComment, PullRequestId, PullRequestState, RepoId, |
| 4 | }; |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 12 | pub struct PullRequestCounts { |
| 13 | pub open: u64, |
| 14 | pub merged: u64, |
| 15 | pub closed: u64, |
| 16 | } |
| 17 | |
| 18 | impl PullRequestCounts { |
| 19 | |
| 20 | pub fn of(self, state: PullRequestState) -> u64 { |
| 21 | match state { |
| 22 | PullRequestState::Open => self.open, |
| 23 | PullRequestState::Merged => self.merged, |
| 24 | PullRequestState::Closed => self.closed, |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | pub trait PullRequestRepository: Send + Sync { |
| 41 | |
| 42 | fn find_by_number( |
| 43 | &self, |
| 44 | repo_id: &RepoId, |
| 45 | number: IssueNumber, |
| 46 | ) -> impl Future<Output = RepositoryResult<Option<PullRequest>>> + Send; |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | fn list_by_repo( |
| 54 | &self, |
| 55 | repo_id: &RepoId, |
| 56 | state: PullRequestState, |
| 57 | offset: usize, |
| 58 | limit: usize, |
| 59 | ) -> impl Future<Output = RepositoryResult<Vec<PullRequest>>> + Send; |
| 60 | |
| 61 | |
| 62 | fn counts( |
| 63 | &self, |
| 64 | repo_id: &RepoId, |
| 65 | ) -> impl Future<Output = RepositoryResult<PullRequestCounts>> + Send; |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | fn comment_counts( |
| 72 | &self, |
| 73 | repo_id: &RepoId, |
| 74 | ) -> impl Future<Output = RepositoryResult<Vec<(PullRequestId, u64)>>> + Send; |
| 75 | |
| 76 | |
| 77 | fn save(&self, pull: &PullRequest) -> impl Future<Output = RepositoryResult<()>> + Send; |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | fn list_comments( |
| 85 | &self, |
| 86 | pull_request_id: &PullRequestId, |
| 87 | ) -> impl Future<Output = RepositoryResult<Vec<PullRequestComment>>> + Send; |
| 88 | |
| 89 | |
| 90 | fn add_comment( |
| 91 | &self, |
| 92 | comment: &PullRequestComment, |
| 93 | ) -> impl Future<Output = RepositoryResult<()>> + Send; |
| 94 | } |