gr/
github.rs

1use crate::config::ConfigProperties;
2use crate::http::Headers;
3use std::sync::Arc;
4
5pub mod cicd;
6pub mod container_registry;
7pub mod gist;
8pub mod merge_request;
9pub mod project;
10pub mod release;
11pub mod trending;
12pub mod user;
13
14#[derive(Clone)]
15pub struct Github<R> {
16    api_token: String,
17    domain: String,
18    path: String,
19    rest_api_basepath: String,
20    runner: Arc<R>,
21}
22
23impl<R> Github<R> {
24    pub fn new(
25        config: Arc<dyn ConfigProperties>,
26        domain: &str,
27        path: &str,
28        runner: Arc<R>,
29    ) -> Self {
30        let api_token = config.api_token().to_string();
31        let domain = domain.to_string();
32        let rest_api_basepath = format!("https://api.{domain}");
33
34        Github {
35            api_token,
36            domain,
37            path: path.to_string(),
38            rest_api_basepath,
39            runner,
40        }
41    }
42
43    fn request_headers(&self) -> Headers {
44        let mut headers = Headers::new();
45        let auth_token_value = format!("bearer {}", self.api_token);
46        headers.set("Authorization".to_string(), auth_token_value);
47        headers.set(
48            "Accept".to_string(),
49            "application/vnd.github.v3+json".to_string(),
50        );
51        headers.set("User-Agent".to_string(), "gitar".to_string());
52        headers.set("X-GitHub-Api-Version".to_string(), "2022-11-28".to_string());
53        headers
54    }
55}