feat: add apierror & activity todos, fix clippy warnings

This commit is contained in:
RobWalt 2023-08-24 18:06:19 +02:00
parent 8cc41b7dc6
commit 4ac0460145
No known key found for this signature in database
GPG key ID: 333C6AC0CEF0CE68
16 changed files with 42 additions and 23 deletions

View file

@ -66,9 +66,9 @@ macro_rules! implement_boolean_enum {
mod from {
use super::$enum_name;
impl Into<bool> 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,
}

15
src/types/api/activity.rs Normal file
View file

@ -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 [...]
// }

View file

@ -0,0 +1,7 @@
// APIError{
// description:
// APIError is an api error with a message
//
// message [...]
// url [...]
// }

View file

@ -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(),

View file

@ -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(),

View file

@ -21,7 +21,7 @@ pub struct ExternalTracker {
}
#[cfg(test)]
mod tracker {
mod tracker_tests {
use std::str::FromStr;
use url::Url;

View file

@ -9,7 +9,7 @@ pub struct ExternalWiki {
}
#[cfg(test)]
mod wiki {
mod wiki_tests {
use std::str::FromStr;
use url::Url;

View file

@ -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(),

View file

@ -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;

View file

@ -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",

View file

@ -148,7 +148,7 @@ impl Display for Repository {
}
#[cfg(test)]
mod repository {
mod repository_tests {
use std::str::FromStr;
use chrono::DateTime;

View file

@ -13,7 +13,7 @@ pub struct SearchResults<T> {
}
#[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;

View file

@ -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(

View file

@ -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<Color, _> = serde_json::from_str(&rgb_color_str);
let deserialized: Result<Color, _> = serde_json::from_str(rgb_color_str);
assert!(deserialized.is_err());
}
}

View file

@ -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;

View file

@ -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
}
}