diff --git a/src/types/api/creation/fork.rs b/src/types/api/creation/fork.rs index bb6aec5..0a1a307 100644 --- a/src/types/api/creation/fork.rs +++ b/src/types/api/creation/fork.rs @@ -1,11 +1,10 @@ -//CreateForkOption{ -//description: -//CreateForkOption options for creating a fork -// -//name string -//name of the forked repository -// -//organization string -//organization name, if forking into an organization -// -//} +use serde::{Deserialize, Serialize}; + +/// Options for creating a fork. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct CreateForkOption { + /// The name of the forked repository. + pub name: String, + /// The organization name, if forking into an organization (optional). + pub organization: Option, +} diff --git a/src/types/api/creation/issue.rs b/src/types/api/creation/issue.rs index 4a711aa..70bc474 100644 --- a/src/types/api/creation/issue.rs +++ b/src/types/api/creation/issue.rs @@ -1,24 +1,27 @@ -// CreateIssueOption{ -// description: -// CreateIssueOption options to create one issue -// -// assignee string -// deprecated -// -// assignees [ -// x-go-name: Assignees -// string] -// body string -// closed [...] -// due_date string($date-time) -// labels [ -// x-go-name: Labels -// list of label ids -// -// integer($int64)] -// milestone integer($int64) -// milestone id -// -// ref string -// title* string -// } +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +use crate::types::misc::boolean_enums::state_type::StateType; + +/// Options to create an issue. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct CreateIssueOption { + /// The assignee for the issue (deprecated, use `assignees` instead). + pub assignee: Option, // Deprecated + /// The list of assignees for the issue. + pub assignees: Vec, + /// The body of the issue. + pub body: String, + /// Indicates whether the issue is closed. + pub closed: StateType, + /// The due date for the issue. + pub due_date: Option>, + /// The labels associated with the issue (list of label IDs). + pub labels: Vec, + /// The milestone ID for the issue. + pub milestone: Option, + /// The reference for the issue. + pub ref_field: String, + /// The title of the issue (required). + pub title: String, +} diff --git a/src/types/api/creation/issue_comment.rs b/src/types/api/creation/issue_comment.rs index d20ab3e..05f867a 100644 --- a/src/types/api/creation/issue_comment.rs +++ b/src/types/api/creation/issue_comment.rs @@ -1,6 +1,8 @@ -// CreateIssueCommentOption{ -// description: -// CreateIssueCommentOption options for creating a comment on an issue -// -// body* string -// } +use serde::{Deserialize, Serialize}; + +/// Options for creating a comment on an issue. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct CreateIssueCommentOption { + /// The body of the comment. This field is required. + pub body: String, +} diff --git a/src/types/api/creation/milestone.rs b/src/types/api/creation/milestone.rs index 6b867da..727006f 100644 --- a/src/types/api/creation/milestone.rs +++ b/src/types/api/creation/milestone.rs @@ -1,11 +1,15 @@ -// CreateMilestoneOption{ -// description: -// CreateMilestoneOption options for creating a milestone -// -// description string -// due_on string($date-time) -// state string -// Enum: -// [ open, closed ] -// title string -// } +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +/// Options for creating a milestone. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct CreateMilestoneOption { + /// The description of the milestone. + pub description: Option, + /// The due date for the milestone. + pub due_on: Option>, + /// The state of the milestone (open or closed). + pub state: String, + /// The title of the milestone. + pub title: String, +} diff --git a/src/types/api/creation/pull_request.rs b/src/types/api/creation/pull_request.rs index c4f82c9..f4fb619 100644 --- a/src/types/api/creation/pull_request.rs +++ b/src/types/api/creation/pull_request.rs @@ -1,18 +1,25 @@ -// CreatePullRequestOption{ -// description: -// CreatePullRequestOption options when creating a pull request -// -// assignee string -// assignees [ -// x-go-name: Assignees -// string] -// base string -// body string -// due_date string($date-time) -// head string -// labels [ -// x-go-name: Labels -// integer($int64)] -// milestone integer($int64) -// title string -// } +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +/// Options for creating a pull request. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct CreatePullRequestOption { + /// The assignee for the pull request. + pub assignee: Option, + /// The list of assignees for the pull request. + pub assignees: Vec, + /// The base branch for the pull request. + pub base: String, + /// The body of the pull request. + pub body: String, + /// The due date for the pull request. + pub due_date: Option>, + /// The head branch for the pull request. + pub head: String, + /// The labels associated with the pull request (list of label IDs). + pub labels: Vec, + /// The milestone ID for the pull request. + pub milestone: Option, + /// The title of the pull request. + pub title: String, +} diff --git a/src/types/api/edit/issue.rs b/src/types/api/edit/issue.rs index 8f09d4d..ead6e3c 100644 --- a/src/types/api/edit/issue.rs +++ b/src/types/api/edit/issue.rs @@ -1,18 +1,27 @@ -// EditIssueOption{ -// description: -// EditIssueOption options for editing an issue -// -// assignee string -// deprecated -// -// assignees [ -// x-go-name: Assignees -// string] -// body string -// due_date string($date-time) -// milestone integer($int64) -// ref string -// state string -// title string -// unset_due_date boolean -// } +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +use crate::types::misc::boolean_enums::unset_due_date::UnsetDueDate; + +/// Options for editing an issue. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct EditIssueOption { + /// The assignee for the issue (deprecated, use `assignees` instead). + pub assignee: Option, // Deprecated + /// The list of assignees for the issue. + pub assignees: Vec, + /// The body of the issue. + pub body: String, + /// The due date for the issue. + pub due_date: Option>, + /// The milestone ID for the issue. + pub milestone: Option, + /// The reference for the issue. + pub ref_field: String, + /// The state of the issue. ["open" / "closed"] + pub state: String, + /// The title of the issue. + pub title: String, + /// Indicates whether to unset the due date. + pub unset_due_date: UnsetDueDate, +} diff --git a/src/types/api/edit/milestone.rs b/src/types/api/edit/milestone.rs index 1968a3e..19509c8 100644 --- a/src/types/api/edit/milestone.rs +++ b/src/types/api/edit/milestone.rs @@ -1,9 +1,15 @@ -// EditMilestoneOption{ -// description: -// EditMilestoneOption options for editing a milestone -// -// description string -// due_on string($date-time) -// state string -// title string -// } +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +/// Options for editing a milestone. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct EditMilestoneOption { + /// The description of the milestone. + pub description: Option, + /// The due date for the milestone. + pub due_on: Option>, + /// The state of the milestone (open or closed). + pub state: String, + /// The title of the milestone. + pub title: String, +} diff --git a/src/types/api/edit/pull_request.rs b/src/types/api/edit/pull_request.rs index da3aa52..f0679ef 100644 --- a/src/types/api/edit/pull_request.rs +++ b/src/types/api/edit/pull_request.rs @@ -1,20 +1,32 @@ -// EditPullRequestOption{ -// description: -// EditPullRequestOption options when modify pull request -// -// allow_maintainer_edit boolean -// assignee string -// assignees [ -// x-go-name: Assignees -// string] -// base string -// body string -// due_date string($date-time) -// labels [ -// x-go-name: Labels -// integer($int64)] -// milestone integer($int64) -// state string -// title string -// unset_due_date boolean -// } +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +use crate::types::misc::boolean_enums::allow::maintainer_edit::AllowMaintainerEdit; +use crate::types::misc::boolean_enums::unset_due_date::UnsetDueDate; + +/// Options for modifying a pull request. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct EditPullRequestOption { + /// Allow maintainers to edit the pull request. + pub allow_maintainer_edit: AllowMaintainerEdit, + /// The assignee for the pull request. (deprecated use assignees) + pub assignee: Option, // deprecated + /// The list of assignees for the pull request. + pub assignees: Vec, + /// The base branch for the pull request. + pub base: String, + /// The body of the pull request. + pub body: String, + /// The due date for the pull request. + pub due_date: Option>, + /// The labels associated with the pull request (list of label IDs). + pub labels: Vec, + /// The milestone ID for the pull request. + pub milestone: Option, + /// The state of the pull request. ["open" / "closed"] + pub state: String, + /// The title of the pull request. + pub title: String, + /// Indicates whether to unset the due date. + pub unset_due_date: UnsetDueDate, +} diff --git a/src/types/api/mod.rs b/src/types/api/mod.rs index 0e36112..39b6d24 100644 --- a/src/types/api/mod.rs +++ b/src/types/api/mod.rs @@ -91,6 +91,7 @@ pub mod access_token; /* to-todo */ pub mod note; /* to-todo */ pub mod notification_count; /* to-todo */ pub mod notification_subject; +/* to-todo */ pub mod notification_subject_type; /* to-todo */ pub mod notification_thread; /* to-todo */ pub mod notify_subject_type; /* to-todo */ pub mod oath_application; diff --git a/src/types/api/notification_count.rs b/src/types/api/notification_count.rs index 6af6eff..aeb484a 100644 --- a/src/types/api/notification_count.rs +++ b/src/types/api/notification_count.rs @@ -1,6 +1,15 @@ -//NotificationCount{ -//description: -//NotificationCount number of unread notifications -// -//new integer($int64) -//} +use serde::{Deserialize, Serialize}; + +use crate::define_deserialize_test; + +/// Represents the number of unread notifications. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct NotificationCount { + /// The number of new unread notifications. + pub new: usize, +} + +define_deserialize_test!( + NotificationCount, + "../../../test_data/example_notification_count.json" +); diff --git a/src/types/api/notification_subject.rs b/src/types/api/notification_subject.rs index cf27db0..b0d931a 100644 --- a/src/types/api/notification_subject.rs +++ b/src/types/api/notification_subject.rs @@ -1,12 +1,30 @@ -//NotificationSubject{ -//description: -//NotificationSubject contains the notification subject (Issue/Pull/Commit) -// -//html_url string -//latest_comment_html_url string -//latest_comment_url string -//state StateType[...] -//title string -//type NotifySubjectType[...] -//url string -//} +use serde::{Deserialize, Serialize}; +use url::Url; + +use crate::define_deserialize_test; +use crate::types::misc::boolean_enums::state_type::StateType; +use crate::types::api::notification_subject_type::NotifySubjectType; + +/// Represents the notification subject, which can be an Issue, Pull Request, or Commit. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct NotificationSubject { + /// The HTML URL of the notification subject. + pub html_url: Url, + /// The HTML URL of the latest comment on the notification subject. + pub latest_comment_html_url: Url, + /// The URL of the latest comment on the notification subject. + pub latest_comment_url: Url, + /// The state of the notification subject (e.g., "open" or "closed"). + pub state: StateType, + /// The title of the notification subject. + pub title: String, + /// The type of the notification subject (e.g., "Issue", "PullRequest", or "Commit"). + pub r#type: NotifySubjectType, + /// The URL of the notification subject. + pub url: Url, +} + +define_deserialize_test!( + NotificationSubject, + "../../../test_data/example_notification_subject.json" +); diff --git a/src/types/api/notification_subject_type.rs b/src/types/api/notification_subject_type.rs new file mode 100644 index 0000000..600cbdf --- /dev/null +++ b/src/types/api/notification_subject_type.rs @@ -0,0 +1,35 @@ +use serde::{Deserialize, Serialize}; + +/// Represents the type of the notification subject. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub enum NotifySubjectType { + Issue, + PullRequest, + Commit, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn deserialize_notify_subject_type_issue() { + let json_data = r#""Issue""#; + let notify_subject_type: NotifySubjectType = serde_json::from_str(json_data).unwrap(); + assert_eq!(notify_subject_type, NotifySubjectType::Issue); + } + + #[test] + fn deserialize_notify_subject_type_pull_request() { + let json_data = r#""PullRequest""#; + let notify_subject_type: NotifySubjectType = serde_json::from_str(json_data).unwrap(); + assert_eq!(notify_subject_type, NotifySubjectType::PullRequest); + } + + #[test] + fn deserialize_notify_subject_type_commit() { + let json_data = r#""Commit""#; + let notify_subject_type: NotifySubjectType = serde_json::from_str(json_data).unwrap(); + assert_eq!(notify_subject_type, NotifySubjectType::Commit); + } +} diff --git a/src/types/api/notification_thread.rs b/src/types/api/notification_thread.rs index a6a726b..e31e5fc 100644 --- a/src/types/api/notification_thread.rs +++ b/src/types/api/notification_thread.rs @@ -1,12 +1,33 @@ -//NotificationThread{ -//description: -//NotificationThread expose Notification on API -// -//id integer($int64) -//pinned boolean -//repository Repository{...} -//subject NotificationSubject{...} -//unread boolean -//updated_at string($date-time) -//url string -//} +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use url::Url; + +use crate::define_deserialize_test; +use crate::types::api::notification_subject::NotificationSubject; +use crate::types::api::repository::Repository; +use crate::types::misc::boolean_enums::is::pinned::IsPinned; +use crate::types::misc::boolean_enums::is::unread::IsUnread; + +/// Represents a NotificationThread. +#[derive(Debug, Serialize, Deserialize)] +pub struct NotificationThread { + /// The ID of the notification thread. + pub id: usize, + /// Indicates whether the thread is pinned. + pub pinned: IsPinned, + /// The repository associated with the thread. + pub repository: Repository, + /// The subject of the notification thread. + pub subject: NotificationSubject, + /// Indicates whether the thread is unread. + pub unread: IsUnread, + /// The timestamp when the thread was last updated. + pub updated_at: DateTime, + /// The URL of the notification thread. + pub url: Url, +} + +define_deserialize_test!( + NotificationThread, + "../../../test_data/example_notification_thread.json" +); diff --git a/src/types/api/replace/label.rs b/src/types/api/replace/label.rs index 0b41c8e..94b1252 100644 --- a/src/types/api/replace/label.rs +++ b/src/types/api/replace/label.rs @@ -1,10 +1,8 @@ -// IssueLabelsOption{ -// description: -// IssueLabelsOption a collection of labels -// -// labels [ -// x-go-name: Labels -// list of label IDs -// -// integer($int64)] -// } +use serde::{Deserialize, Serialize}; + +/// A collection of labels for an issue. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct IssueLabelsOption { + /// List of label IDs associated with the issue. + pub labels: Vec, +} diff --git a/src/types/misc/boolean_enums/is/mod.rs b/src/types/misc/boolean_enums/is/mod.rs index 9c8d805..f7a6c36 100644 --- a/src/types/misc/boolean_enums/is/mod.rs +++ b/src/types/misc/boolean_enums/is/mod.rs @@ -18,3 +18,5 @@ implement_boolean_enum!(mergeable, IsMergeable); implement_boolean_enum!(merged, IsMerged); implement_boolean_enum!(verified, IsVerified); implement_boolean_enum!(protected, IsProtected); +implement_boolean_enum!(pinned, IsPinned); +implement_boolean_enum!(unread, IsUnread); diff --git a/src/types/misc/boolean_enums/mod.rs b/src/types/misc/boolean_enums/mod.rs index 73f6882..0227aa6 100644 --- a/src/types/misc/boolean_enums/mod.rs +++ b/src/types/misc/boolean_enums/mod.rs @@ -12,3 +12,4 @@ implement_boolean_enum!(includes_all_repositories, IncludesAllRepositories); implement_boolean_enum!(prohibit_login, ProhibitLogin); implement_boolean_enum!(auto_init, AutoInit); implement_boolean_enum!(state_type, StateType { Open, Closed }); +implement_boolean_enum!(unset_due_date, UnsetDueDate { Unset, Keep }); diff --git a/test_data/example_notification_count.json b/test_data/example_notification_count.json new file mode 100644 index 0000000..8a45b34 --- /dev/null +++ b/test_data/example_notification_count.json @@ -0,0 +1,3 @@ +{ + "new": 10 +} diff --git a/test_data/example_notification_subject.json b/test_data/example_notification_subject.json new file mode 100644 index 0000000..ac2cd26 --- /dev/null +++ b/test_data/example_notification_subject.json @@ -0,0 +1,9 @@ +{ + "html_url": "https://example.com/issue/123", + "latest_comment_html_url": "https://example.com/issue/123#comment-456", + "latest_comment_url": "https://api.example.com/issues/123/comments/456", + "state": "open", + "title": "Example Issue", + "type": "Issue", + "url": "https://api.example.com/issues/123" +} diff --git a/test_data/example_notification_thread.json b/test_data/example_notification_thread.json new file mode 100644 index 0000000..997d646 --- /dev/null +++ b/test_data/example_notification_thread.json @@ -0,0 +1,98 @@ +{ + "id": 123, + "pinned": false, + "repository": { + "id": 128746, + "owner": { + "active": true, + "avatar_url": "https://codeberg.org/avatars/foo-bar", + "created": "2022-11-04T14:41:29Z", + "description": "", + "email": "example@mail.com", + "followers_count": 2, + "following_count": 1, + "full_name": "", + "id": 12345, + "is_admin": false, + "language": "en-US", + "last_login": "2023-07-26T19:38:27Z", + "location": "", + "login": "ExampleUser", + "login_name": "", + "prohibit_login": false, + "restricted": false, + "starred_repos_count": 0, + "username": "ExampleUser", + "visibility": "public", + "website": "https://example.com" + }, + "name": "tmp", + "full_name": "VoiDD/tmp", + "description": "", + "empty": true, + "private": false, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 24, + "language": "", + "languages_url": "https://codeberg.org/api/v1/repos/VoiDD/tmp/languages", + "html_url": "https://codeberg.org/VoiDD/tmp", + "link": "", + "ssh_url": "git@codeberg.org:VoiDD/tmp.git", + "clone_url": "https://codeberg.org/VoiDD/tmp.git", + "original_url": "", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 1, + "open_issues_count": 0, + "open_pr_counter": 0, + "release_counter": 0, + "default_branch": "main", + "archived": false, + "created_at": "2023-07-27T18:59:48Z", + "updated_at": "2023-07-27T18:59:48Z", + "permissions": { + "admin": true, + "pull": false, + "push": true + }, + "has_issues": true, + "internal_tracker": { + "allow_only_contributors_to_track_time": true, + "enable_issue_dependencies": false, + "enable_time_tracker": true + }, + "has_wiki": true, + "has_pull_requests": true, + "has_projects": true, + "ignore_whitespace_conflicts": false, + "allow_merge_commits": true, + "allow_rebase": true, + "allow_rebase_explicit": true, + "allow_squash_merge": true, + "allow_rebase_update": true, + "default_delete_branch_after_merge": false, + "default_merge_style": "merge", + "default_allow_maintainer_edit": false, + "avatar_url": "", + "internal": false, + "mirror_interval": "", + "mirror_updated": "0001-01-01T00:00:00Z", + "repo_transfer": null + }, + "subject": { + "html_url": "https://example.com/issue/123", + "latest_comment_html_url": "https://example.com/issue/123#comment-456", + "latest_comment_url": "https://api.example.com/issues/123/comments/456", + "state": "open", + "title": "Example Issue", + "type": "Issue", + "url": "https://api.example.com/issues/123" + }, + "unread": true, + "updated_at": "2023-10-21T14:30:00Z", + "url": "https://api.example.com/notification/123" +}