diff --git a/Cargo.lock b/Cargo.lock index bf5414a..2552da0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,7 +224,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "forgejo-api-types" -version = "0.1.3" +version = "0.1.4" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 2c40b95..d9c77e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "forgejo-api-types" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "AGPL-3.0-or-later" keywords = ["forgejo", "types", "codeberg", "api"] diff --git a/src/types/api/creation/repository.rs b/src/types/api/creation/repository.rs index 7c3f116..52f277c 100644 --- a/src/types/api/creation/repository.rs +++ b/src/types/api/creation/repository.rs @@ -6,7 +6,7 @@ use crate::types::misc::boolean_enums::is::template::IsTemplate; use crate::types::misc::trust_model::TrustModel; /// CreateRepoOption represents options when creating a repository. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, PartialEq)] pub struct CreateRepoOption { /// Whether the repository should be auto-initialized. pub auto_init: AutoInit, @@ -14,10 +14,11 @@ pub struct CreateRepoOption { pub default_branch: String, /// Description of the repository to create. pub description: String, + // 🚧🚧 TODO 🚧🚧 : This can probably be enumerated /// Gitignores to use. pub gitignores: String, - /// Label-Set to use. // 🚧🚧 TODO 🚧🚧 : Do better than comma separated list of names + /// Label-Set to use. pub issue_labels: String, /// License to use. pub license: String, @@ -47,3 +48,28 @@ impl Default for CreateRepoOption { } } } + +#[test] +fn test_create_repo_option_serialization_deserialization() { + // Create a sample CreateRepoOption instance + let repo_option = CreateRepoOption { + auto_init: AutoInit::Yes, + default_branch: String::from("main"), + description: String::from("An empty repository."), + gitignores: String::from("rust"), + issue_labels: String::from("bug,feature"), + license: String::from("MIT"), + name: String::from("NewRepo"), + private: IsPrivate::Yes, + template: IsTemplate::No, + trust_model: TrustModel::Default, + }; + + let data = include_str!("../../../../test_data/example_create_repo_option.json"); + + // Deserialize the JSON string back to a CreateRepoOption instance + let deserialized: CreateRepoOption = serde_json::from_str(data).unwrap(); + + // Verify that the original and deserialized instances are equal + assert_eq!(repo_option, deserialized); +} diff --git a/src/types/api/milestone.rs b/src/types/api/milestone.rs index 21e65ca..1bf2705 100644 --- a/src/types/api/milestone.rs +++ b/src/types/api/milestone.rs @@ -15,3 +15,59 @@ // title string // updated_at string($date-time) // } + +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +use crate::types::misc::boolean_enums::state_type::StateType; + +/// Milestone represents a collection of issues on one repository. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct Milestone { + /// The timestamp when the milestone was closed. + pub closed_at: Option>, + /// The number of closed issues in the milestone. + pub closed_issues: usize, + /// The timestamp when the milestone was created. + pub created_at: DateTime, + /// The description of the milestone. + pub description: String, + /// The due date for the milestone. + pub due_on: Option>, + /// The unique ID of the milestone. + pub id: usize, + /// The number of open issues in the milestone. + pub open_issues: usize, + /// The state of the milestone. + pub state: StateType, + /// The title of the milestone. + pub title: String, + /// The timestamp when the milestone was last updated. + pub updated_at: DateTime, +} + +#[test] +fn test_milestone_serialization_deserialization() { + use std::str::FromStr; + + // Create a sample Milestone instance with predefined values for testing. + let milestone = Milestone { + closed_at: Some(DateTime::from_str("2023-09-22T22:04:43.456694702Z").unwrap()), + closed_issues: 10, + created_at: DateTime::from_str("2023-09-22T22:04:43.456699822Z").unwrap(), + description: String::from("Sample milestone description"), + due_on: Some(DateTime::from_str("2023-09-22T22:04:43.456705994Z").unwrap()), + id: 123, + open_issues: 5, + state: StateType::Open, + title: String::from("Sample Milestone"), + updated_at: DateTime::from_str("2023-09-22T22:04:43.456706164Z").unwrap(), + }; + + // Deserialize the JSON string back into a Milestone instance. + let deserialized: Milestone = + serde_json::from_str(include_str!("../../../test_data/example_milestone.json")).unwrap(); + + // Verify that the original and deserialized instances are equal. + assert_eq!(milestone, deserialized); +} diff --git a/src/types/api/mod.rs b/src/types/api/mod.rs index 38541fb..0e36112 100644 --- a/src/types/api/mod.rs +++ b/src/types/api/mod.rs @@ -116,7 +116,6 @@ pub mod access_token; /* to-todo */ pub mod repository_settings; /* to-todo */ pub mod review_state; /* to-todo */ pub mod server_verion; -/* to-todo */ pub mod state_type; /* to-todo */ pub mod stop_watch; /* to-todo */ pub mod submit_pull_review; /* to-todo */ pub mod tag; diff --git a/src/types/api/pull_request.rs b/src/types/api/pull_request.rs index d5c172e..dd7138d 100644 --- a/src/types/api/pull_request.rs +++ b/src/types/api/pull_request.rs @@ -36,3 +36,133 @@ // url string // user User{...} // }] + +use crate::types::api::label::Label; +use crate::types::api::milestone::Milestone; +use crate::types::api::pull_request_branch_info::PRBranchInfo; +use crate::types::api::user::User; +use crate::types::misc::boolean_enums::allow::maintainer_edit::AllowMaintainerEdit; +use crate::types::misc::boolean_enums::is::locked::IsLocked; +use crate::types::misc::boolean_enums::is::mergeable::IsMergeable; +use crate::types::misc::boolean_enums::is::merged::IsMerged; +use crate::types::misc::boolean_enums::state_type::StateType; +use crate::types::misc::optional_url::OptionalUrl; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use url::Url; + +/// PullRequest represents a pull request. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PullRequest { + /// Whether the pull request allows maintainer edits. + pub allow_maintainer_edit: AllowMaintainerEdit, + /// The assignee of the pull request. + pub assignee: User, + /// The list of assignees for the pull request. + pub assignees: Vec, + /// Information about the base branch. + pub base: PRBranchInfo, + /// The body (description) of the pull request. + pub body: String, + /// The timestamp when the pull request was closed. + pub closed_at: DateTime, + /// The number of comments on the pull request. + pub comments: usize, + /// The timestamp when the pull request was created. + pub created_at: DateTime, + /// The URL to view the diff for the pull request. + pub diff_url: OptionalUrl, + /// The due date for the pull request. + pub due_date: DateTime, + /// Information about the head branch. + pub head: PRBranchInfo, + /// The HTML URL for viewing the pull request. + pub html_url: OptionalUrl, + /// The unique ID of the pull request. + pub id: usize, + /// Whether the pull request is locked. + pub is_locked: IsLocked, + /// The labels associated with the pull request. + pub labels: Vec