From 4ac0460145e8f6e828f020feb11c5ca22679785d Mon Sep 17 00:00:00 2001 From: RobWalt Date: Thu, 24 Aug 2023 18:06:19 +0200 Subject: [PATCH] feat: add apierror & activity todos, fix clippy warnings --- src/macros.rs | 6 +++--- src/types/api/activity.rs | 15 +++++++++++++++ src/types/api/api_error.rs | 7 +++++++ src/types/api/creation/label.rs | 2 +- src/types/api/edit/label.rs | 2 +- src/types/api/external/tracker.rs | 2 +- src/types/api/external/wiki.rs | 2 +- src/types/api/label.rs | 2 +- src/types/api/mod.rs | 2 ++ src/types/api/organization.rs | 2 +- src/types/api/repository.rs | 2 +- src/types/api/search_results.rs | 2 +- src/types/api/user.rs | 2 +- src/types/misc/color.rs | 6 +++--- src/types/misc/header.rs | 2 +- src/types/misc/team_permissions.rs | 9 ++------- 16 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 src/types/api/activity.rs create mode 100644 src/types/api/api_error.rs diff --git a/src/macros.rs b/src/macros.rs index 042cdcb..84bccc8 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -66,9 +66,9 @@ macro_rules! implement_boolean_enum { mod from { use super::$enum_name; - impl Into for $enum_name { - fn into(self) -> bool { - match self { + impl From<$enum_name> for bool { + fn from(val: $enum_name) -> Self { + match val { $enum_name::$yes_variant => true, $enum_name::$no_variant => false, } diff --git a/src/types/api/activity.rs b/src/types/api/activity.rs new file mode 100644 index 0000000..13a3630 --- /dev/null +++ b/src/types/api/activity.rs @@ -0,0 +1,15 @@ +// Activity{ +// act_user User{...} +// act_user_id [...] +// comment Comment{...} +// comment_id [...] +// content [...] +// created [...] +// id [...] +// is_private [...] +// op_type [...] +// ref_name [...] +// repo Repository{...} +// repo_id [...] +// user_id [...] +// } diff --git a/src/types/api/api_error.rs b/src/types/api/api_error.rs new file mode 100644 index 0000000..0fcc4f7 --- /dev/null +++ b/src/types/api/api_error.rs @@ -0,0 +1,7 @@ +// APIError{ +// description: +// APIError is an api error with a message +// +// message [...] +// url [...] +// } diff --git a/src/types/api/creation/label.rs b/src/types/api/creation/label.rs index ba1b44e..8bebf51 100644 --- a/src/types/api/creation/label.rs +++ b/src/types/api/creation/label.rs @@ -35,7 +35,7 @@ mod tests { #[test] fn deserialize_create_label_option() { let json_data = include_str!("../../../../test_data/example_create_label.json"); - let option: CreateLabelOption = serde_json::from_str(&json_data).unwrap(); + let option: CreateLabelOption = serde_json::from_str(json_data).unwrap(); let expected = CreateLabelOption { color: Color(Rgb::new(0x00, 0xaa, 0xbb)), description: "CreateLabelOption options for creating a label".to_string(), diff --git a/src/types/api/edit/label.rs b/src/types/api/edit/label.rs index 59dda96..b936e03 100644 --- a/src/types/api/edit/label.rs +++ b/src/types/api/edit/label.rs @@ -35,7 +35,7 @@ mod tests { #[test] fn deserialize_edit_label_option() { let json_data = include_str!("../../../../test_data/example_edit_label.json"); - let option: CreateLabelOption = serde_json::from_str(&json_data).unwrap(); + let option: CreateLabelOption = serde_json::from_str(json_data).unwrap(); let expected = CreateLabelOption { color: Color(Rgb::new(0x00, 0xaa, 0xbb)), description: "EditLabelOption options for updating a label".to_string(), diff --git a/src/types/api/external/tracker.rs b/src/types/api/external/tracker.rs index c97ffc9..1fbb530 100644 --- a/src/types/api/external/tracker.rs +++ b/src/types/api/external/tracker.rs @@ -21,7 +21,7 @@ pub struct ExternalTracker { } #[cfg(test)] -mod tracker { +mod tracker_tests { use std::str::FromStr; use url::Url; diff --git a/src/types/api/external/wiki.rs b/src/types/api/external/wiki.rs index 0374299..2afaab2 100644 --- a/src/types/api/external/wiki.rs +++ b/src/types/api/external/wiki.rs @@ -9,7 +9,7 @@ pub struct ExternalWiki { } #[cfg(test)] -mod wiki { +mod wiki_tests { use std::str::FromStr; use url::Url; diff --git a/src/types/api/label.rs b/src/types/api/label.rs index 87fc9dd..985705c 100644 --- a/src/types/api/label.rs +++ b/src/types/api/label.rs @@ -43,7 +43,7 @@ mod tests { #[test] fn deserialize_label() { let data = include_str!("../../../test_data/example_label.json"); - let label: Label = serde_json::from_str(&data).unwrap(); + let label: Label = serde_json::from_str(data).unwrap(); let expected = Label { color: Color(Rgb::from_str("00aabb").unwrap()), description: "Label a label to an issue or a pr".to_string(), diff --git a/src/types/api/mod.rs b/src/types/api/mod.rs index 5a1180b..8ea8c3b 100644 --- a/src/types/api/mod.rs +++ b/src/types/api/mod.rs @@ -14,9 +14,11 @@ pub mod user; /* to-todo */ pub mod access_token; +/* to-todo */ pub mod activity; /* to-todo */ pub mod add; /* to-todo */ pub mod annotated_tag; /* to-todo */ pub mod annotated_tag_object; +/* to-todo */ pub mod api_error; /* to-todo */ pub mod api_settings; /* to-todo */ pub mod attachment; /* to-todo */ pub mod attachment_settings; diff --git a/src/types/api/organization.rs b/src/types/api/organization.rs index e3a9952..0017999 100644 --- a/src/types/api/organization.rs +++ b/src/types/api/organization.rs @@ -48,7 +48,7 @@ mod tests { #[test] fn deserialize_works() { let data = include_str!("../../../test_data/example_organization.json"); - let org: Organization = serde_json::from_str(&data).unwrap(); + let org: Organization = serde_json::from_str(data).unwrap(); let expected = Organization { avatar_url: Url::from_str( "https://codeberg.org/avatars/9efc314b65237d5d646e1b817372afc6", diff --git a/src/types/api/repository.rs b/src/types/api/repository.rs index c238032..3be05bb 100644 --- a/src/types/api/repository.rs +++ b/src/types/api/repository.rs @@ -148,7 +148,7 @@ impl Display for Repository { } #[cfg(test)] -mod repository { +mod repository_tests { use std::str::FromStr; use chrono::DateTime; diff --git a/src/types/api/search_results.rs b/src/types/api/search_results.rs index 4cf9e19..33084b8 100644 --- a/src/types/api/search_results.rs +++ b/src/types/api/search_results.rs @@ -13,7 +13,7 @@ pub struct SearchResults { } #[cfg(test)] -mod search_results { +mod search_results_tests { use crate::types::api::search_results::SearchResults; use crate::types::api::team::Team; use crate::types::misc::boolean_enums::is::ok::IsOk; diff --git a/src/types/api/user.rs b/src/types/api/user.rs index 5ac4fa9..27a8094 100644 --- a/src/types/api/user.rs +++ b/src/types/api/user.rs @@ -85,7 +85,7 @@ mod tests { #[test] fn deserialize_works() { let data = include_str!("../../../test_data/example_user.json"); - let user: User = serde_json::from_str(&data).unwrap(); + let user: User = serde_json::from_str(data).unwrap(); let expected = User { active: IsActive::Yes, avatar_url: OptionalUrl::Some( diff --git a/src/types/misc/color.rs b/src/types/misc/color.rs index f0c66a5..fbc2c4c 100644 --- a/src/types/misc/color.rs +++ b/src/types/misc/color.rs @@ -70,7 +70,7 @@ impl<'de> Deserialize<'de> for Color { } #[cfg(test)] -mod color { +mod color_tests { use palette::rgb::Rgb; use crate::types::misc::color::Color; @@ -91,7 +91,7 @@ mod color { let rgb_color = Color(Rgb::new(0x64, 0x32, 0xc8)); let rgb_color_str = "\"#6432c8\""; - let deserialized: Color = serde_json::from_str(&rgb_color_str).unwrap(); + let deserialized: Color = serde_json::from_str(rgb_color_str).unwrap(); assert_eq!(deserialized, rgb_color); } @@ -100,7 +100,7 @@ mod color { // Example of serializing and deserializing let rgb_color_str = "\"##6432c8\""; - let deserialized: Result = serde_json::from_str(&rgb_color_str); + let deserialized: Result = serde_json::from_str(rgb_color_str); assert!(deserialized.is_err()); } } diff --git a/src/types/misc/header.rs b/src/types/misc/header.rs index 79e8984..49ec546 100644 --- a/src/types/misc/header.rs +++ b/src/types/misc/header.rs @@ -73,7 +73,7 @@ impl<'de> Deserialize<'de> for Header { } #[cfg(test)] -mod header { +mod header_tests { use hyper::http::{HeaderName, HeaderValue}; use crate::types::misc::header::Header; diff --git a/src/types/misc/team_permissions.rs b/src/types/misc/team_permissions.rs index 7a7dbe1..2e88c7d 100644 --- a/src/types/misc/team_permissions.rs +++ b/src/types/misc/team_permissions.rs @@ -2,18 +2,13 @@ use serde::{Deserialize, Serialize}; use strum::{Display, EnumIs}; /// Permission level of the team -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Display, EnumIs)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Display, EnumIs, Default)] #[serde(rename_all = "lowercase")] pub enum TeamPermission { + #[default] None, Read, Write, Admin, Owner, } - -impl Default for TeamPermission { - fn default() -> Self { - TeamPermission::None - } -}