~/selfhut

selfhut/src/utils/repo_config.rs -rw-r--r-- 721 B
532ca616 — Arthur Melton format 2 years ago
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::git::file::file;
use crate::git::main_branch::main_branch;
use serde_derive::{Deserialize, Serialize};

pub fn repo_config(repo: String) -> RepoConfig {
    let main_branch = main_branch(repo.clone()).unwrap_or("".to_string());
    let content = match file(repo.clone(), main_branch.clone(), "repo.toml".to_string()) {
        Some(file) => file.1.unwrap_or("".to_string()),
        None => "".to_string(),
    };
    match toml::from_str(&content) {
        Ok(x) => x,
        Err(_) => RepoConfig {
            description: None,
            website: None,
        },
    }
}

#[derive(Deserialize, Serialize)]
pub struct RepoConfig {
    pub description: Option<String>,
    pub website: Option<String>,
}