hubcaps/
app.rs

1//! Labels interface
2use serde::Deserialize;
3
4use self::super::{AuthenticationConstraint, Future, Github, MediaType};
5
6pub struct App {
7    github: Github,
8}
9
10impl App {
11    #[doc(hidden)]
12    pub(crate) fn new(github: Github) -> Self {
13        App { github }
14    }
15
16    fn path(&self, more: &str) -> String {
17        format!("/app{}", more)
18    }
19
20    pub fn make_access_token(&self, installation_id: u64) -> Future<AccessToken> {
21        self.github.post_media::<AccessToken>(
22            &self.path(&format!("/installations/{}/access_tokens", installation_id)),
23            Vec::new(),
24            MediaType::Preview("machine-man"),
25            AuthenticationConstraint::JWT,
26        )
27    }
28
29    pub fn find_repo_installation<O, R>(&self, owner: O, repo: R) -> Future<Installation>
30    where
31        O: Into<String>,
32        R: Into<String>,
33    {
34        self.github.get_media::<Installation>(
35            &format!("/repos/{}/{}/installation", owner.into(), repo.into()),
36            MediaType::Preview("machine-man"),
37        )
38    }
39}
40
41// representations
42
43#[derive(Debug, Deserialize)]
44pub struct AccessToken {
45    pub token: String,
46    pub expires_at: String,
47}
48
49#[derive(Debug, Deserialize)]
50pub struct Installation {
51    pub id: u64,
52    // account: Account
53    pub access_tokens_url: String,
54    pub repositories_url: String,
55    pub html_url: String,
56    pub app_id: i32,
57    pub target_id: i32,
58    pub target_type: String,
59    // permissions: Permissions
60    pub events: Vec<String>,
61    // created_at, updated_at
62    pub single_file_name: Option<String>,
63    pub repository_selection: String,
64}