Skip to main content

gitv_tui/github/
mod.rs

1use crate::errors::AppError;
2
3pub struct GithubClient {
4    inner: octocrab::Octocrab,
5}
6
7impl std::ops::Deref for GithubClient {
8    type Target = octocrab::Octocrab;
9
10    fn deref(&self) -> &Self::Target {
11        &self.inner
12    }
13}
14
15impl GithubClient {
16    pub fn new(token: Option<String>) -> Result<Self, AppError> {
17        let mut builder = octocrab::Octocrab::builder();
18        if let Some(token) = token {
19            builder = builder.personal_token(token);
20        }
21        let inner = builder.build()?;
22        Ok(Self { inner })
23    }
24
25    pub fn inner(&self) -> &octocrab::Octocrab {
26        &self.inner
27    }
28}