url_preview/
github_types.rs

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
38
39
40
41
42
43
44
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct GitHubRepository {
    pub name: String,
    pub full_name: String,
    pub description: Option<String>,
    pub stargazers_count: u32,
    pub forks_count: u32,
    pub language: Option<String>,
    pub open_issues_count: u32,
    pub watchers_count: u32,
    pub subscribers_count: u32,
    pub owner: GitHubOwner,
    pub topics: Vec<String>,
    pub html_url: String,
}

#[derive(Debug, Deserialize)]
pub struct GitHubOwner {
    pub login: String,
    pub avatar_url: String,
}

pub fn is_github_url(url: &str) -> bool {
    url.contains("github.com")
}

#[derive(Debug, Clone)]
pub struct GitHubBasicPreview {
    pub title: String,
    pub description: Option<String>,
    pub image_url: Option<String>,
}

#[derive(Debug, Clone)]
pub struct GitHubDetailedInfo {
    pub stars_count: u32,
    pub forks_count: u32,
    pub contributors_count: u32,
    pub issues_count: u32,
    pub discussions_count: u32,
    pub primary_language: Option<String>,
}