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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
use chrono::prelude::{DateTime, Utc};
use serde::Deserialize;
use crate::{Result, User};
#[derive(Debug, Deserialize)]
pub struct Repo {
id: u64,
node_id: String,
name: String,
full_name: String,
private: bool,
owner: User,
html_url: String,
description: String,
fork: bool,
url: String,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
pushed_at: DateTime<Utc>,
git_url: String,
ssh_url: String,
clone_url: String,
svn_url: String,
homepage: String,
size: u64,
stargazers_count: u64,
language: Option<String>,
forks_count: u64,
archived: bool,
disabled: bool,
has_projects: bool,
has_pages: bool,
has_downloads: bool,
open_issues: u64,
default_branch: String,
subscribers_count: u64,
has_issues: bool,
has_wiki: bool,
open_issues_count: u64,
}
impl Repo {
pub async fn new(user: &str, repo: &str, user_agent: &str) -> Result<Self> {
let repo: Repo = reqwest::Client::builder()
.user_agent(user_agent)
.build()?
.get(&repo_api_url(user, repo))
.send()
.await?
.json()
.await?;
Ok(repo)
}
pub fn id(&self) -> u64 {
self.id
}
pub fn node_id(&self) -> &str {
&self.node_id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn full_name(&self) -> &str {
&self.full_name
}
pub fn private(&self) -> bool {
self.private
}
pub fn owner(&self) -> &User {
&self.owner
}
pub fn html_url(&self) -> &str {
&self.html_url
}
pub fn description(&self) -> &str {
&self.description
}
pub fn fork(&self) -> bool {
self.fork
}
pub fn url(&self) -> &str {
&self.url
}
pub fn created_at(&self) -> &DateTime<Utc> {
&self.created_at
}
pub fn updated_at(&self) -> &DateTime<Utc> {
&self.updated_at
}
pub fn pushed_at(&self) -> &DateTime<Utc> {
&self.pushed_at
}
pub fn git_url(&self) -> &str {
&self.git_url
}
pub fn ssh_url(&self) -> &str {
&self.ssh_url
}
pub fn clone_url(&self) -> &str {
&self.clone_url
}
pub fn svn_url(&self) -> &str {
&self.svn_url
}
pub fn homepage(&self) -> &str {
&self.homepage
}
pub fn size(&self) -> u64 {
self.size
}
pub fn stargazers_count(&self) -> u64 {
self.stargazers_count
}
pub fn language(&self) -> &Option<String> {
&self.language
}
pub fn forks_count(&self) -> u64 {
self.forks_count
}
pub fn archived(&self) -> bool {
self.archived
}
pub fn disabled(&self) -> bool {
self.disabled
}
pub fn has_projects(&self) -> bool {
self.has_projects
}
pub fn has_pages(&self) -> bool {
self.has_pages
}
pub fn has_downloads(&self) -> bool {
self.has_downloads
}
pub fn open_issues(&self) -> u64 {
self.open_issues
}
pub fn default_branch(&self) -> &str {
&self.default_branch
}
pub fn subscribers_count(&self) -> u64 {
self.subscribers_count
}
pub fn has_issues(&self) -> bool {
self.has_issues
}
pub fn has_wiki(&self) -> bool {
self.has_wiki
}
pub fn open_issues_count(&self) -> u64 {
self.open_issues_count
}
}
fn repo_api_url(user: &str, repo: &str) -> String {
const URL: &str = "https://api.github.com/repos";
format!("{}/{}/{}", URL, user, repo)
}