-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepo.rs
More file actions
37 lines (31 loc) · 1.04 KB
/
repo.rs
File metadata and controls
37 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#[cfg(test)]
use mockall::automock;
use octocrab::models::repos::Release;
use octocrab::Octocrab;
use crate::errors::{InternalError, Result};
use crate::game_data::Repo;
#[cfg_attr(test, automock(type Pager = Vec<Release>;))]
pub trait RepoFetcher {
type Pager: IntoIterator<Item = Release>;
async fn get_releases(&self, repo: &Repo) -> Result<Self::Pager>;
async fn get_last_release(&self, repo: &Repo) -> Result<Release>;
}
impl RepoFetcher for Octocrab {
type Pager = std::vec::IntoIter<Release>;
async fn get_releases(&self, repo: &Repo) -> Result<<Self as RepoFetcher>::Pager> {
Ok(self
.repos(repo.owner(), repo.repository())
.releases()
.list()
.send()
.await?
.into_iter())
}
async fn get_last_release(&self, repo: &Repo) -> Result<Release> {
self.repos(repo.owner(), repo.repository())
.releases()
.get_latest()
.await
.map_err(|err| InternalError::External(Box::new(err)))
}
}