automatons-github 0.3.0

GitHub integration for the automatons framework
Documentation
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
use std::fmt::{Display, Formatter};

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use url::Url;

use crate::resource::{Account, License, NodeId, Visibility};
use crate::{id, name};

pub use self::minimal::MinimalRepository;

mod minimal;

id!(
    /// Repository id
    ///
    /// The [`RepositoryId`] is a unique, numerical id that is used to interact with an account
    /// through [GitHub's REST API](https://docs.github.com/en/rest).
    RepositoryId
);

name!(
    /// Repository name
    ///
    /// Repositories on GitHub have a human-readable name that is used throughout GitHub's
    /// website. The name is unique within the scope of its owner.
    RepositoryName
);

name!(
    /// Repository owner and name
    ///
    /// The full name of a repository is a unique combination of the repository's owner and name.
    RepositoryFullName
);

/// Repository on GitHub
///
/// Repositories are a core resource on GitHub, and most other resources belong to them. They are
/// uniquely identified by the combination of their `owner` and `name`.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Deserialize, Serialize)]
pub struct Repository {
    #[serde(flatten)]
    minimal: MinimalRepository,

    node_id: NodeId,
    owner: Account,
    full_name: RepositoryFullName,
    description: String,
    homepage: String,
    language: String,
    license: License,
    visibility: Visibility,
    default_branch: String,
    topics: Vec<String>,
    size: u64,
    stargazers_count: u64,
    watchers_count: u64,
    forks_count: u64,
    open_issues_count: u64,
    private: bool,
    fork: bool,
    has_issues: bool,
    has_projects: bool,
    has_wiki: bool,
    has_pages: bool,
    archived: bool,
    disabled: bool,
    allow_forking: bool,
    is_template: bool,
    web_commit_signoff_required: bool,
    html_url: Url,
    keys_url: Url,
    collaborators_url: Url,
    teams_url: Url,
    hooks_url: Url,
    issue_events_url: Url,
    events_url: Url,
    assignees_url: Url,
    branches_url: Url,
    tags_url: Url,
    blobs_url: Url,
    git_tags_url: Url,
    git_refs_url: Url,
    trees_url: Url,
    statuses_url: Url,
    languages_url: Url,
    stargazers_url: Url,
    contributors_url: Url,
    subscribers_url: Url,
    subscription_url: Url,
    commits_url: Url,
    git_commits_url: Url,
    comments_url: Url,
    issue_comment_url: Url,
    contents_url: Url,
    compare_url: Url,
    merges_url: Url,
    archive_url: Url,
    downloads_url: Url,
    issues_url: Url,
    pulls_url: Url,
    milestones_url: Url,
    notifications_url: Url,
    labels_url: Url,
    releases_url: Url,
    deployments_url: Url,
    git_url: Url,
    ssh_url: String,
    clone_url: Url,
    svn_url: Url,
    mirror_url: Option<Url>,
    created_at: DateTime<Utc>,
    updated_at: DateTime<Utc>,
    pushed_at: DateTime<Utc>,
}

impl Repository {
    /// Returns the repository's unique id.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn id(&self) -> RepositoryId {
        self.minimal.id()
    }

    /// Returns the repository's node id.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn node_id(&self) -> &NodeId {
        &self.node_id
    }

    /// Returns the repository's name.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn name(&self) -> &RepositoryName {
        self.minimal.name()
    }

    /// Returns the account which ows the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn owner(&self) -> &Account {
        &self.owner
    }

    /// Returns the repository's full name.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn full_name(&self) -> &RepositoryFullName {
        &self.full_name
    }

    /// Returns the repository's description.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn description(&self) -> &String {
        &self.description
    }

    /// Returns the URL to the repository's homepage.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn homepage(&self) -> &String {
        &self.homepage
    }

    /// Returns the repository's primary programming language.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn language(&self) -> &String {
        &self.language
    }

    /// Returns the repository's license.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn license(&self) -> &License {
        &self.license
    }

    /// Returns the repository's visibility.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn visibility(&self) -> Visibility {
        self.visibility
    }

    /// Returns the repository's default branch.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn default_branch(&self) -> &String {
        &self.default_branch
    }

    /// Returns the repository's topics.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn topics(&self) -> &Vec<String> {
        &self.topics
    }

    /// Returns the repository's size.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn size(&self) -> u64 {
        self.size
    }

    /// Returns the repository's stargazers count.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn stargazers_count(&self) -> u64 {
        self.stargazers_count
    }

    /// Returns the repository's watchers count.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn watchers_count(&self) -> u64 {
        self.watchers_count
    }

    /// Returns the repository's forks count.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn forks_count(&self) -> u64 {
        self.forks_count
    }

    /// Returns the repository's open issues count.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn open_issues_count(&self) -> u64 {
        self.open_issues_count
    }

    /// Indicates whether the repository is private.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn private(&self) -> bool {
        self.private
    }

    /// Indicates whether the repository is a fork.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn fork(&self) -> bool {
        self.fork
    }

    /// Indicates whether the issues feature is enabled for the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn has_issues(&self) -> bool {
        self.has_issues
    }

    /// Indicates whether the projects feature is enabled for the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn has_projects(&self) -> bool {
        self.has_projects
    }

    /// Indicates whether the wiki feature is enabled for the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn has_wiki(&self) -> bool {
        self.has_wiki
    }

    /// Indicates whether the repository has a static website.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn has_pages(&self) -> bool {
        self.has_pages
    }

    /// Indicates whether the repository has been archived.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn archived(&self) -> bool {
        self.archived
    }

    /// Indicates whether the repository has been disabled.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn disabled(&self) -> bool {
        self.disabled
    }

    /// Indicates whether the repository can be forked.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn allow_forking(&self) -> bool {
        self.allow_forking
    }

    /// Indicates whether the repository can be used as a template.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn is_template(&self) -> bool {
        self.is_template
    }

    /// Indicates whether the signoff is required for commits through GitHub's web interface.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn web_commit_signoff_required(&self) -> bool {
        self.web_commit_signoff_required
    }

    /// Returns the URL to the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn html_url(&self) -> &Url {
        &self.html_url
    }

    /// Returns the API endpoint to query the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn url(&self) -> &Url {
        self.minimal.url()
    }

    /// Returns the API endpoint to query the repository's keys.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn keys_url(&self) -> &Url {
        &self.keys_url
    }

    /// Returns the API endpoint to query the repository's collaborators.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn collaborators_url(&self) -> &Url {
        &self.collaborators_url
    }

    /// Returns the API endpoint to query the repository's teams.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn teams_url(&self) -> &Url {
        &self.teams_url
    }

    /// Returns the API endpoint to query the repository's hooks.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn hooks_url(&self) -> &Url {
        &self.hooks_url
    }

    /// Returns the API endpoint to query the repository's issue events.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn issue_events_url(&self) -> &Url {
        &self.issue_events_url
    }

    /// Returns the API endpoint to query the repository's events.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn events_url(&self) -> &Url {
        &self.events_url
    }

    /// Returns the API endpoint to query the repository's assignees.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn assignees_url(&self) -> &Url {
        &self.assignees_url
    }

    /// Returns the API endpoint to query the repository's branches.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn branches_url(&self) -> &Url {
        &self.branches_url
    }

    /// Returns the API endpoint to query the repository's tags.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn tags_url(&self) -> &Url {
        &self.tags_url
    }

    /// Returns the API endpoint to query the repository's blobs.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn blobs_url(&self) -> &Url {
        &self.blobs_url
    }

    /// Returns the API endpoint to query the repository's git tags.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn git_tags_url(&self) -> &Url {
        &self.git_tags_url
    }

    /// Returns the API endpoint to query the repository's git refs.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn git_refs_url(&self) -> &Url {
        &self.git_refs_url
    }

    /// Returns the API endpoint to query the repository's git trees.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn trees_url(&self) -> &Url {
        &self.trees_url
    }

    /// Returns the API endpoint to query the repository's statuses.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn statuses_url(&self) -> &Url {
        &self.statuses_url
    }

    /// Returns the API endpoint to query the repository's programming languages.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn languages_url(&self) -> &Url {
        &self.languages_url
    }

    /// Returns the API endpoint to query the repository's stargazers.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn stargazers_url(&self) -> &Url {
        &self.stargazers_url
    }

    /// Returns the API endpoint to query the repository's contributors.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn contributors_url(&self) -> &Url {
        &self.contributors_url
    }

    /// Returns the API endpoint to query the repository's subscribers.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn subscribers_url(&self) -> &Url {
        &self.subscribers_url
    }

    /// Returns the API endpoint to query the repository's subscriptions.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn subscription_url(&self) -> &Url {
        &self.subscription_url
    }

    /// Returns the API endpoint to query the repository's commits.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn commits_url(&self) -> &Url {
        &self.commits_url
    }

    /// Returns the API endpoint to query the repository's git commits.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn git_commits_url(&self) -> &Url {
        &self.git_commits_url
    }

    /// Returns the API endpoint to query the repository's comments.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn comments_url(&self) -> &Url {
        &self.comments_url
    }

    /// Returns the API endpoint to query the repository's issue comments.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn issue_comment_url(&self) -> &Url {
        &self.issue_comment_url
    }

    /// Returns the API endpoint to query the repository's contents.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn contents_url(&self) -> &Url {
        &self.contents_url
    }

    /// Returns the API endpoint to compare refs in the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn compare_url(&self) -> &Url {
        &self.compare_url
    }

    /// Returns the API endpoint to query the repository's merges.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn merges_url(&self) -> &Url {
        &self.merges_url
    }

    /// Returns the API endpoint to retrieve the repository's archive.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn archive_url(&self) -> &Url {
        &self.archive_url
    }

    /// Returns the API endpoint to query the repository's downloads.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn downloads_url(&self) -> &Url {
        &self.downloads_url
    }

    /// Returns the API endpoint to query the repository's issues.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn issues_url(&self) -> &Url {
        &self.issues_url
    }

    /// Returns the API endpoint to query the repository's pull requests.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn pulls_url(&self) -> &Url {
        &self.pulls_url
    }

    /// Returns the API endpoint to query the repository's milestones.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn milestones_url(&self) -> &Url {
        &self.milestones_url
    }

    /// Returns the API endpoint to query the repository's notifications.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn notifications_url(&self) -> &Url {
        &self.notifications_url
    }

    /// Returns the API endpoint to query the repository's labels.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn labels_url(&self) -> &Url {
        &self.labels_url
    }

    /// Returns the API endpoint to query the repository's releases.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn releases_url(&self) -> &Url {
        &self.releases_url
    }

    /// Returns the API endpoint to query the repository's deployments.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn deployments_url(&self) -> &Url {
        &self.deployments_url
    }

    /// Returns the Git URL to clone the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn git_url(&self) -> &Url {
        &self.git_url
    }

    /// Returns the SSH URL to clone the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn ssh_url(&self) -> &str {
        &self.ssh_url
    }

    /// Returns the HTTP URL to clone the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn clone_url(&self) -> &Url {
        &self.clone_url
    }

    /// Returns the SVN URL to clone the repository.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn svn_url(&self) -> &Url {
        &self.svn_url
    }

    /// Returns the URL to the repository's mirror.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn mirror_url(&self) -> &Option<Url> {
        &self.mirror_url
    }

    /// Returns the date when the repository was created.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn created_at(&self) -> &DateTime<Utc> {
        &self.created_at
    }

    /// Returns the date when the repository was last updated.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn updated_at(&self) -> &DateTime<Utc> {
        &self.updated_at
    }

    /// Returns the date when the repository was last pushed.
    #[cfg_attr(feature = "tracing", tracing::instrument)]
    pub fn pushed_at(&self) -> &DateTime<Utc> {
        &self.pushed_at
    }
}

impl Display for Repository {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.full_name)
    }
}

#[cfg(test)]
mod tests {
    use super::Repository;

    #[test]
    fn trait_deserialize() {
        let repository: Repository = serde_json::from_str(include_str!(
            "../../../tests/fixtures/resource/repository.json"
        ))
        .unwrap();

        assert_eq!("automatons", repository.name().get());
    }

    #[test]
    fn trait_display() {
        let repository: Repository = serde_json::from_str(include_str!(
            "../../../tests/fixtures/resource/repository.json"
        ))
        .unwrap();

        assert_eq!("devxbots/automatons", repository.to_string());
    }

    #[test]
    fn trait_send() {
        fn assert_send<T: Send>() {}
        assert_send::<Repository>();
    }

    #[test]
    fn trait_sync() {
        fn assert_sync<T: Sync>() {}
        assert_sync::<Repository>();
    }
}