automatons_github/resource/repository/
mod.rs1use std::fmt::{Display, Formatter};
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use url::Url;
6
7use crate::resource::{Account, License, NodeId, Visibility};
8use crate::{id, name};
9
10pub use self::minimal::MinimalRepository;
11
12mod minimal;
13
14id!(
15 RepositoryId
20);
21
22name!(
23 RepositoryName
28);
29
30name!(
31 RepositoryFullName
35);
36
37#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Deserialize, Serialize)]
42pub struct Repository {
43 #[serde(flatten)]
44 minimal: MinimalRepository,
45
46 node_id: NodeId,
47 owner: Account,
48 full_name: RepositoryFullName,
49 description: String,
50 homepage: String,
51 language: String,
52 license: License,
53 visibility: Visibility,
54 default_branch: String,
55 topics: Vec<String>,
56 size: u64,
57 stargazers_count: u64,
58 watchers_count: u64,
59 forks_count: u64,
60 open_issues_count: u64,
61 private: bool,
62 fork: bool,
63 has_issues: bool,
64 has_projects: bool,
65 has_wiki: bool,
66 has_pages: bool,
67 archived: bool,
68 disabled: bool,
69 allow_forking: bool,
70 is_template: bool,
71 web_commit_signoff_required: bool,
72 html_url: Url,
73 keys_url: Url,
74 collaborators_url: Url,
75 teams_url: Url,
76 hooks_url: Url,
77 issue_events_url: Url,
78 events_url: Url,
79 assignees_url: Url,
80 branches_url: Url,
81 tags_url: Url,
82 blobs_url: Url,
83 git_tags_url: Url,
84 git_refs_url: Url,
85 trees_url: Url,
86 statuses_url: Url,
87 languages_url: Url,
88 stargazers_url: Url,
89 contributors_url: Url,
90 subscribers_url: Url,
91 subscription_url: Url,
92 commits_url: Url,
93 git_commits_url: Url,
94 comments_url: Url,
95 issue_comment_url: Url,
96 contents_url: Url,
97 compare_url: Url,
98 merges_url: Url,
99 archive_url: Url,
100 downloads_url: Url,
101 issues_url: Url,
102 pulls_url: Url,
103 milestones_url: Url,
104 notifications_url: Url,
105 labels_url: Url,
106 releases_url: Url,
107 deployments_url: Url,
108 git_url: Url,
109 ssh_url: String,
110 clone_url: Url,
111 svn_url: Url,
112 mirror_url: Option<Url>,
113 created_at: DateTime<Utc>,
114 updated_at: DateTime<Utc>,
115 pushed_at: DateTime<Utc>,
116}
117
118impl Repository {
119 #[cfg_attr(feature = "tracing", tracing::instrument)]
121 pub fn id(&self) -> RepositoryId {
122 self.minimal.id()
123 }
124
125 #[cfg_attr(feature = "tracing", tracing::instrument)]
127 pub fn node_id(&self) -> &NodeId {
128 &self.node_id
129 }
130
131 #[cfg_attr(feature = "tracing", tracing::instrument)]
133 pub fn name(&self) -> &RepositoryName {
134 self.minimal.name()
135 }
136
137 #[cfg_attr(feature = "tracing", tracing::instrument)]
139 pub fn owner(&self) -> &Account {
140 &self.owner
141 }
142
143 #[cfg_attr(feature = "tracing", tracing::instrument)]
145 pub fn full_name(&self) -> &RepositoryFullName {
146 &self.full_name
147 }
148
149 #[cfg_attr(feature = "tracing", tracing::instrument)]
151 pub fn description(&self) -> &String {
152 &self.description
153 }
154
155 #[cfg_attr(feature = "tracing", tracing::instrument)]
157 pub fn homepage(&self) -> &String {
158 &self.homepage
159 }
160
161 #[cfg_attr(feature = "tracing", tracing::instrument)]
163 pub fn language(&self) -> &String {
164 &self.language
165 }
166
167 #[cfg_attr(feature = "tracing", tracing::instrument)]
169 pub fn license(&self) -> &License {
170 &self.license
171 }
172
173 #[cfg_attr(feature = "tracing", tracing::instrument)]
175 pub fn visibility(&self) -> Visibility {
176 self.visibility
177 }
178
179 #[cfg_attr(feature = "tracing", tracing::instrument)]
181 pub fn default_branch(&self) -> &String {
182 &self.default_branch
183 }
184
185 #[cfg_attr(feature = "tracing", tracing::instrument)]
187 pub fn topics(&self) -> &Vec<String> {
188 &self.topics
189 }
190
191 #[cfg_attr(feature = "tracing", tracing::instrument)]
193 pub fn size(&self) -> u64 {
194 self.size
195 }
196
197 #[cfg_attr(feature = "tracing", tracing::instrument)]
199 pub fn stargazers_count(&self) -> u64 {
200 self.stargazers_count
201 }
202
203 #[cfg_attr(feature = "tracing", tracing::instrument)]
205 pub fn watchers_count(&self) -> u64 {
206 self.watchers_count
207 }
208
209 #[cfg_attr(feature = "tracing", tracing::instrument)]
211 pub fn forks_count(&self) -> u64 {
212 self.forks_count
213 }
214
215 #[cfg_attr(feature = "tracing", tracing::instrument)]
217 pub fn open_issues_count(&self) -> u64 {
218 self.open_issues_count
219 }
220
221 #[cfg_attr(feature = "tracing", tracing::instrument)]
223 pub fn private(&self) -> bool {
224 self.private
225 }
226
227 #[cfg_attr(feature = "tracing", tracing::instrument)]
229 pub fn fork(&self) -> bool {
230 self.fork
231 }
232
233 #[cfg_attr(feature = "tracing", tracing::instrument)]
235 pub fn has_issues(&self) -> bool {
236 self.has_issues
237 }
238
239 #[cfg_attr(feature = "tracing", tracing::instrument)]
241 pub fn has_projects(&self) -> bool {
242 self.has_projects
243 }
244
245 #[cfg_attr(feature = "tracing", tracing::instrument)]
247 pub fn has_wiki(&self) -> bool {
248 self.has_wiki
249 }
250
251 #[cfg_attr(feature = "tracing", tracing::instrument)]
253 pub fn has_pages(&self) -> bool {
254 self.has_pages
255 }
256
257 #[cfg_attr(feature = "tracing", tracing::instrument)]
259 pub fn archived(&self) -> bool {
260 self.archived
261 }
262
263 #[cfg_attr(feature = "tracing", tracing::instrument)]
265 pub fn disabled(&self) -> bool {
266 self.disabled
267 }
268
269 #[cfg_attr(feature = "tracing", tracing::instrument)]
271 pub fn allow_forking(&self) -> bool {
272 self.allow_forking
273 }
274
275 #[cfg_attr(feature = "tracing", tracing::instrument)]
277 pub fn is_template(&self) -> bool {
278 self.is_template
279 }
280
281 #[cfg_attr(feature = "tracing", tracing::instrument)]
283 pub fn web_commit_signoff_required(&self) -> bool {
284 self.web_commit_signoff_required
285 }
286
287 #[cfg_attr(feature = "tracing", tracing::instrument)]
289 pub fn html_url(&self) -> &Url {
290 &self.html_url
291 }
292
293 #[cfg_attr(feature = "tracing", tracing::instrument)]
295 pub fn url(&self) -> &Url {
296 self.minimal.url()
297 }
298
299 #[cfg_attr(feature = "tracing", tracing::instrument)]
301 pub fn keys_url(&self) -> &Url {
302 &self.keys_url
303 }
304
305 #[cfg_attr(feature = "tracing", tracing::instrument)]
307 pub fn collaborators_url(&self) -> &Url {
308 &self.collaborators_url
309 }
310
311 #[cfg_attr(feature = "tracing", tracing::instrument)]
313 pub fn teams_url(&self) -> &Url {
314 &self.teams_url
315 }
316
317 #[cfg_attr(feature = "tracing", tracing::instrument)]
319 pub fn hooks_url(&self) -> &Url {
320 &self.hooks_url
321 }
322
323 #[cfg_attr(feature = "tracing", tracing::instrument)]
325 pub fn issue_events_url(&self) -> &Url {
326 &self.issue_events_url
327 }
328
329 #[cfg_attr(feature = "tracing", tracing::instrument)]
331 pub fn events_url(&self) -> &Url {
332 &self.events_url
333 }
334
335 #[cfg_attr(feature = "tracing", tracing::instrument)]
337 pub fn assignees_url(&self) -> &Url {
338 &self.assignees_url
339 }
340
341 #[cfg_attr(feature = "tracing", tracing::instrument)]
343 pub fn branches_url(&self) -> &Url {
344 &self.branches_url
345 }
346
347 #[cfg_attr(feature = "tracing", tracing::instrument)]
349 pub fn tags_url(&self) -> &Url {
350 &self.tags_url
351 }
352
353 #[cfg_attr(feature = "tracing", tracing::instrument)]
355 pub fn blobs_url(&self) -> &Url {
356 &self.blobs_url
357 }
358
359 #[cfg_attr(feature = "tracing", tracing::instrument)]
361 pub fn git_tags_url(&self) -> &Url {
362 &self.git_tags_url
363 }
364
365 #[cfg_attr(feature = "tracing", tracing::instrument)]
367 pub fn git_refs_url(&self) -> &Url {
368 &self.git_refs_url
369 }
370
371 #[cfg_attr(feature = "tracing", tracing::instrument)]
373 pub fn trees_url(&self) -> &Url {
374 &self.trees_url
375 }
376
377 #[cfg_attr(feature = "tracing", tracing::instrument)]
379 pub fn statuses_url(&self) -> &Url {
380 &self.statuses_url
381 }
382
383 #[cfg_attr(feature = "tracing", tracing::instrument)]
385 pub fn languages_url(&self) -> &Url {
386 &self.languages_url
387 }
388
389 #[cfg_attr(feature = "tracing", tracing::instrument)]
391 pub fn stargazers_url(&self) -> &Url {
392 &self.stargazers_url
393 }
394
395 #[cfg_attr(feature = "tracing", tracing::instrument)]
397 pub fn contributors_url(&self) -> &Url {
398 &self.contributors_url
399 }
400
401 #[cfg_attr(feature = "tracing", tracing::instrument)]
403 pub fn subscribers_url(&self) -> &Url {
404 &self.subscribers_url
405 }
406
407 #[cfg_attr(feature = "tracing", tracing::instrument)]
409 pub fn subscription_url(&self) -> &Url {
410 &self.subscription_url
411 }
412
413 #[cfg_attr(feature = "tracing", tracing::instrument)]
415 pub fn commits_url(&self) -> &Url {
416 &self.commits_url
417 }
418
419 #[cfg_attr(feature = "tracing", tracing::instrument)]
421 pub fn git_commits_url(&self) -> &Url {
422 &self.git_commits_url
423 }
424
425 #[cfg_attr(feature = "tracing", tracing::instrument)]
427 pub fn comments_url(&self) -> &Url {
428 &self.comments_url
429 }
430
431 #[cfg_attr(feature = "tracing", tracing::instrument)]
433 pub fn issue_comment_url(&self) -> &Url {
434 &self.issue_comment_url
435 }
436
437 #[cfg_attr(feature = "tracing", tracing::instrument)]
439 pub fn contents_url(&self) -> &Url {
440 &self.contents_url
441 }
442
443 #[cfg_attr(feature = "tracing", tracing::instrument)]
445 pub fn compare_url(&self) -> &Url {
446 &self.compare_url
447 }
448
449 #[cfg_attr(feature = "tracing", tracing::instrument)]
451 pub fn merges_url(&self) -> &Url {
452 &self.merges_url
453 }
454
455 #[cfg_attr(feature = "tracing", tracing::instrument)]
457 pub fn archive_url(&self) -> &Url {
458 &self.archive_url
459 }
460
461 #[cfg_attr(feature = "tracing", tracing::instrument)]
463 pub fn downloads_url(&self) -> &Url {
464 &self.downloads_url
465 }
466
467 #[cfg_attr(feature = "tracing", tracing::instrument)]
469 pub fn issues_url(&self) -> &Url {
470 &self.issues_url
471 }
472
473 #[cfg_attr(feature = "tracing", tracing::instrument)]
475 pub fn pulls_url(&self) -> &Url {
476 &self.pulls_url
477 }
478
479 #[cfg_attr(feature = "tracing", tracing::instrument)]
481 pub fn milestones_url(&self) -> &Url {
482 &self.milestones_url
483 }
484
485 #[cfg_attr(feature = "tracing", tracing::instrument)]
487 pub fn notifications_url(&self) -> &Url {
488 &self.notifications_url
489 }
490
491 #[cfg_attr(feature = "tracing", tracing::instrument)]
493 pub fn labels_url(&self) -> &Url {
494 &self.labels_url
495 }
496
497 #[cfg_attr(feature = "tracing", tracing::instrument)]
499 pub fn releases_url(&self) -> &Url {
500 &self.releases_url
501 }
502
503 #[cfg_attr(feature = "tracing", tracing::instrument)]
505 pub fn deployments_url(&self) -> &Url {
506 &self.deployments_url
507 }
508
509 #[cfg_attr(feature = "tracing", tracing::instrument)]
511 pub fn git_url(&self) -> &Url {
512 &self.git_url
513 }
514
515 #[cfg_attr(feature = "tracing", tracing::instrument)]
517 pub fn ssh_url(&self) -> &str {
518 &self.ssh_url
519 }
520
521 #[cfg_attr(feature = "tracing", tracing::instrument)]
523 pub fn clone_url(&self) -> &Url {
524 &self.clone_url
525 }
526
527 #[cfg_attr(feature = "tracing", tracing::instrument)]
529 pub fn svn_url(&self) -> &Url {
530 &self.svn_url
531 }
532
533 #[cfg_attr(feature = "tracing", tracing::instrument)]
535 pub fn mirror_url(&self) -> &Option<Url> {
536 &self.mirror_url
537 }
538
539 #[cfg_attr(feature = "tracing", tracing::instrument)]
541 pub fn created_at(&self) -> &DateTime<Utc> {
542 &self.created_at
543 }
544
545 #[cfg_attr(feature = "tracing", tracing::instrument)]
547 pub fn updated_at(&self) -> &DateTime<Utc> {
548 &self.updated_at
549 }
550
551 #[cfg_attr(feature = "tracing", tracing::instrument)]
553 pub fn pushed_at(&self) -> &DateTime<Utc> {
554 &self.pushed_at
555 }
556}
557
558impl Display for Repository {
559 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
560 write!(f, "{}", self.full_name)
561 }
562}
563
564#[cfg(test)]
565mod tests {
566 use super::Repository;
567
568 #[test]
569 fn trait_deserialize() {
570 let repository: Repository = serde_json::from_str(include_str!(
571 "../../../tests/fixtures/resource/repository.json"
572 ))
573 .unwrap();
574
575 assert_eq!("automatons", repository.name().get());
576 }
577
578 #[test]
579 fn trait_display() {
580 let repository: Repository = serde_json::from_str(include_str!(
581 "../../../tests/fixtures/resource/repository.json"
582 ))
583 .unwrap();
584
585 assert_eq!("devxbots/automatons", repository.to_string());
586 }
587
588 #[test]
589 fn trait_send() {
590 fn assert_send<T: Send>() {}
591 assert_send::<Repository>();
592 }
593
594 #[test]
595 fn trait_sync() {
596 fn assert_sync<T: Sync>() {}
597 assert_sync::<Repository>();
598 }
599}