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!(
RepositoryId
);
name!(
RepositoryName
);
name!(
RepositoryFullName
);
#[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 {
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn id(&self) -> RepositoryId {
self.minimal.id()
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn node_id(&self) -> &NodeId {
&self.node_id
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn name(&self) -> &RepositoryName {
self.minimal.name()
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn owner(&self) -> &Account {
&self.owner
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn full_name(&self) -> &RepositoryFullName {
&self.full_name
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn description(&self) -> &String {
&self.description
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn homepage(&self) -> &String {
&self.homepage
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn language(&self) -> &String {
&self.language
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn license(&self) -> &License {
&self.license
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn visibility(&self) -> Visibility {
self.visibility
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn default_branch(&self) -> &String {
&self.default_branch
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn topics(&self) -> &Vec<String> {
&self.topics
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn size(&self) -> u64 {
self.size
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn stargazers_count(&self) -> u64 {
self.stargazers_count
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn watchers_count(&self) -> u64 {
self.watchers_count
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn forks_count(&self) -> u64 {
self.forks_count
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn open_issues_count(&self) -> u64 {
self.open_issues_count
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn private(&self) -> bool {
self.private
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn fork(&self) -> bool {
self.fork
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn has_issues(&self) -> bool {
self.has_issues
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn has_projects(&self) -> bool {
self.has_projects
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn has_wiki(&self) -> bool {
self.has_wiki
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn has_pages(&self) -> bool {
self.has_pages
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn archived(&self) -> bool {
self.archived
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn disabled(&self) -> bool {
self.disabled
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn allow_forking(&self) -> bool {
self.allow_forking
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn is_template(&self) -> bool {
self.is_template
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn web_commit_signoff_required(&self) -> bool {
self.web_commit_signoff_required
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn html_url(&self) -> &Url {
&self.html_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn url(&self) -> &Url {
self.minimal.url()
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn keys_url(&self) -> &Url {
&self.keys_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn collaborators_url(&self) -> &Url {
&self.collaborators_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn teams_url(&self) -> &Url {
&self.teams_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn hooks_url(&self) -> &Url {
&self.hooks_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn issue_events_url(&self) -> &Url {
&self.issue_events_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn events_url(&self) -> &Url {
&self.events_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn assignees_url(&self) -> &Url {
&self.assignees_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn branches_url(&self) -> &Url {
&self.branches_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn tags_url(&self) -> &Url {
&self.tags_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn blobs_url(&self) -> &Url {
&self.blobs_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn git_tags_url(&self) -> &Url {
&self.git_tags_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn git_refs_url(&self) -> &Url {
&self.git_refs_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn trees_url(&self) -> &Url {
&self.trees_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn statuses_url(&self) -> &Url {
&self.statuses_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn languages_url(&self) -> &Url {
&self.languages_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn stargazers_url(&self) -> &Url {
&self.stargazers_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn contributors_url(&self) -> &Url {
&self.contributors_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn subscribers_url(&self) -> &Url {
&self.subscribers_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn subscription_url(&self) -> &Url {
&self.subscription_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn commits_url(&self) -> &Url {
&self.commits_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn git_commits_url(&self) -> &Url {
&self.git_commits_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn comments_url(&self) -> &Url {
&self.comments_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn issue_comment_url(&self) -> &Url {
&self.issue_comment_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn contents_url(&self) -> &Url {
&self.contents_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn compare_url(&self) -> &Url {
&self.compare_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn merges_url(&self) -> &Url {
&self.merges_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn archive_url(&self) -> &Url {
&self.archive_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn downloads_url(&self) -> &Url {
&self.downloads_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn issues_url(&self) -> &Url {
&self.issues_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn pulls_url(&self) -> &Url {
&self.pulls_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn milestones_url(&self) -> &Url {
&self.milestones_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn notifications_url(&self) -> &Url {
&self.notifications_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn labels_url(&self) -> &Url {
&self.labels_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn releases_url(&self) -> &Url {
&self.releases_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn deployments_url(&self) -> &Url {
&self.deployments_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn git_url(&self) -> &Url {
&self.git_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn ssh_url(&self) -> &str {
&self.ssh_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn clone_url(&self) -> &Url {
&self.clone_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn svn_url(&self) -> &Url {
&self.svn_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn mirror_url(&self) -> &Option<Url> {
&self.mirror_url
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn created_at(&self) -> &DateTime<Utc> {
&self.created_at
}
#[cfg_attr(feature = "tracing", tracing::instrument)]
pub fn updated_at(&self) -> &DateTime<Utc> {
&self.updated_at
}
#[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>();
}
}