github_rust/github/
models.rs1use crate::github::types::{Language, License};
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Repository {
8 pub node_id: String,
9 pub database_id: Option<u64>,
10 pub name: String,
11 pub name_with_owner: String,
12 pub description: Option<String>,
13 pub url: String,
14 pub homepage_url: Option<String>,
15 pub created_at: String,
17 pub updated_at: String,
19 pub pushed_at: Option<String>,
21 pub is_private: bool,
22 pub is_fork: bool,
23 pub is_archived: bool,
24 pub stargazer_count: u32,
25 pub fork_count: u32,
26 pub watcher_count: Option<u32>,
28 pub open_issue_count: Option<u32>,
30 pub pull_request_count: Option<u32>,
32 pub release_count: Option<u32>,
34 pub primary_language: Option<Language>,
35 pub languages: Option<Vec<LanguageUsage>>,
37 pub languages_complete: bool,
39 pub license_info: Option<License>,
40 pub default_branch: Option<String>,
41 pub topics: Vec<String>,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct LanguageUsage {
46 pub language: Language,
47 pub bytes: u64,
48}
49
50#[derive(Debug, Clone, Default, Serialize, Deserialize)]
52pub struct SearchRepository {
53 pub node_id: String,
54 pub database_id: Option<u64>,
55 pub name: String,
56 pub name_with_owner: String,
57 pub description: Option<String>,
58 pub url: String,
59 pub stargazer_count: u32,
60 pub fork_count: u32,
61 pub created_at: String,
63 pub updated_at: String,
65 pub pushed_at: Option<String>,
67 pub primary_language: Option<Language>,
68 pub license_info: Option<License>,
69 pub topics: Vec<String>,
70}
71
72macro_rules! repository_helpers {
73 ($model:ty) => {
74 impl $model {
75 pub fn language(&self) -> Option<&str> {
76 self.primary_language
77 .as_ref()
78 .map(|language| language.name.as_str())
79 }
80 pub fn license(&self) -> Option<&str> {
81 self.license_info
82 .as_ref()
83 .map(|license| license.name.as_str())
84 }
85 pub fn license_spdx(&self) -> Option<&str> {
86 self.license_info
87 .as_ref()
88 .and_then(|license| license.spdx_id.as_deref())
89 }
90 pub fn topics(&self) -> Vec<&str> {
91 self.topics.iter().map(String::as_str).collect()
92 }
93 pub fn owner(&self) -> &str {
94 self.name_with_owner
95 .split_once('/')
96 .map_or(self.name_with_owner.as_str(), |(owner, _)| owner)
97 }
98 }
99 };
100}
101repository_helpers!(Repository);
102repository_helpers!(SearchRepository);
103
104impl Repository {
105 pub fn default_branch(&self) -> Option<&str> {
106 self.default_branch.as_deref()
107 }
108 pub fn open_issues(&self) -> Option<u32> {
109 self.open_issue_count
110 }
111 pub fn watcher_count(&self) -> Option<u32> {
112 self.watcher_count
113 }
114}