feat: implement a bunch of 'option' types
This commit is contained in:
parent
81d00564f6
commit
076b0c654f
19 changed files with 394 additions and 157 deletions
|
@ -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<String>,
|
||||
}
|
||||
|
|
|
@ -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<String>, // Deprecated
|
||||
/// The list of assignees for the issue.
|
||||
pub assignees: Vec<String>,
|
||||
/// 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<DateTime<Utc>>,
|
||||
/// The labels associated with the issue (list of label IDs).
|
||||
pub labels: Vec<usize>,
|
||||
/// The milestone ID for the issue.
|
||||
pub milestone: Option<usize>,
|
||||
/// The reference for the issue.
|
||||
pub ref_field: String,
|
||||
/// The title of the issue (required).
|
||||
pub title: String,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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<String>,
|
||||
/// The due date for the milestone.
|
||||
pub due_on: Option<DateTime<Utc>>,
|
||||
/// The state of the milestone (open or closed).
|
||||
pub state: String,
|
||||
/// The title of the milestone.
|
||||
pub title: String,
|
||||
}
|
||||
|
|
|
@ -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<String>,
|
||||
/// The list of assignees for the pull request.
|
||||
pub assignees: Vec<String>,
|
||||
/// 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<DateTime<Utc>>,
|
||||
/// The head branch for the pull request.
|
||||
pub head: String,
|
||||
/// The labels associated with the pull request (list of label IDs).
|
||||
pub labels: Vec<usize>,
|
||||
/// The milestone ID for the pull request.
|
||||
pub milestone: Option<usize>,
|
||||
/// The title of the pull request.
|
||||
pub title: String,
|
||||
}
|
||||
|
|
|
@ -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<String>, // Deprecated
|
||||
/// The list of assignees for the issue.
|
||||
pub assignees: Vec<String>,
|
||||
/// The body of the issue.
|
||||
pub body: String,
|
||||
/// The due date for the issue.
|
||||
pub due_date: Option<DateTime<Utc>>,
|
||||
/// The milestone ID for the issue.
|
||||
pub milestone: Option<usize>,
|
||||
/// 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,
|
||||
}
|
||||
|
|
|
@ -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<String>,
|
||||
/// The due date for the milestone.
|
||||
pub due_on: Option<DateTime<Utc>>,
|
||||
/// The state of the milestone (open or closed).
|
||||
pub state: String,
|
||||
/// The title of the milestone.
|
||||
pub title: String,
|
||||
}
|
||||
|
|
|
@ -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<String>, // deprecated
|
||||
/// The list of assignees for the pull request.
|
||||
pub assignees: Vec<String>,
|
||||
/// 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<DateTime<Utc>>,
|
||||
/// The labels associated with the pull request (list of label IDs).
|
||||
pub labels: Vec<usize>,
|
||||
/// The milestone ID for the pull request.
|
||||
pub milestone: Option<usize>,
|
||||
/// 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,
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
);
|
||||
|
|
|
@ -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"
|
||||
);
|
||||
|
|
35
src/types/api/notification_subject_type.rs
Normal file
35
src/types/api/notification_subject_type.rs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<Utc>,
|
||||
/// The URL of the notification thread.
|
||||
pub url: Url,
|
||||
}
|
||||
|
||||
define_deserialize_test!(
|
||||
NotificationThread,
|
||||
"../../../test_data/example_notification_thread.json"
|
||||
);
|
||||
|
|
|
@ -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<usize>,
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 });
|
||||
|
|
3
test_data/example_notification_count.json
Normal file
3
test_data/example_notification_count.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"new": 10
|
||||
}
|
9
test_data/example_notification_subject.json
Normal file
9
test_data/example_notification_subject.json
Normal file
|
@ -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"
|
||||
}
|
98
test_data/example_notification_thread.json
Normal file
98
test_data/example_notification_thread.json
Normal file
|
@ -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"
|
||||
}
|
Loading…
Reference in a new issue