diff --git a/src/types/api/branch.rs b/src/types/api/branch.rs index 79f2744..d25e049 100644 --- a/src/types/api/branch.rs +++ b/src/types/api/branch.rs @@ -14,3 +14,43 @@ // user_can_merge boolean // user_can_push boolean // }] +// +use serde::{Deserialize, Serialize}; + +use crate::types::api::payload_commit::PayloadCommit; +use crate::types::misc::boolean_enums::can::merge::CanMerge; +use crate::types::misc::boolean_enums::can::push::CanPush; +use crate::types::misc::boolean_enums::enable::enable_status_check::EnableStatusCheck; +use crate::types::misc::boolean_enums::is::protected::IsProtected; + +/// Represents a repository branch. +#[derive(Debug, Serialize, Deserialize)] +pub struct Branch { + /// The commit associated with the branch. + pub commit: PayloadCommit, + /// The effective branch protection name. + pub effective_branch_protection_name: String, + /// Indicates whether status checks are enabled for the branch. + pub enable_status_check: EnableStatusCheck, + /// The name of the branch. + pub name: String, + /// Indicates whether the branch is protected. + pub protected: IsProtected, + /// The number of required approvals for the branch. + pub required_approvals: usize, + /// Contexts for status checks. + pub status_check_contexts: Vec, + /// Indicates whether the user can merge into the branch. + pub user_can_merge: CanMerge, + /// Indicates whether the user can push to the branch. + pub user_can_push: CanPush, +} + +#[cfg(test)] +mod tests { + #[test] + fn deserialize_branches() { + let data = include_str!("../../../test_data/example_branch.json"); + let _: Vec = serde_json::from_str(data).unwrap(); + } +} diff --git a/src/types/api/payload_commit.rs b/src/types/api/payload_commit.rs index 79343f9..34a2c6b 100644 --- a/src/types/api/payload_commit.rs +++ b/src/types/api/payload_commit.rs @@ -1,23 +1,41 @@ -// PayloadCommit{ -// description: -// PayloadCommit represents a commit -// -// added [ -// x-go-name: Added -// string] -// author PayloadUser{...} -// committer PayloadUser{...} -// id string -// sha1 hash of the commit -// -// message string -// modified [ -// x-go-name: Modified -// string] -// removed [ -// x-go-name: Removed -// string] -// timestamp string($date-time) -// url string -// verification PayloadCommitVerification{...} -// } +use std::path::PathBuf; + +use crate::types::api::payload_commit_verification::PayloadCommitVerification; +use crate::types::api::payload_user::PayloadUser; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use url::Url; + +/// Represents a commit payload. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PayloadCommit { + /// List of added files. + pub added: Vec, + /// The author of the commit. + pub author: PayloadUser, + /// The committer of the commit. + pub committer: PayloadUser, + /// The SHA1 hash of the commit. + pub id: String, + /// The commit message. + pub message: String, + /// List of modified files. + pub modified: Vec, + /// List of removed files. + pub removed: Vec, + /// The timestamp of the commit. + pub timestamp: DateTime, + /// The URL of the commit. + pub url: Url, + /// Verification information for the commit. + pub verification: PayloadCommitVerification, +} + +#[cfg(test)] +mod tests { + #[test] + fn deserialize_payload_commit() { + let data = include_str!("../../../test_data/example_payload_commit.json"); + let _: super::PayloadCommit = serde_json::from_str(data).unwrap(); + } +} diff --git a/src/types/api/payload_commit_verification.rs b/src/types/api/payload_commit_verification.rs index 724fad1..c2f3507 100644 --- a/src/types/api/payload_commit_verification.rs +++ b/src/types/api/payload_commit_verification.rs @@ -1,11 +1,28 @@ -// PayloadCommitVerification{ -// description: -// PayloadCommitVerification represents the GPG verification of a commit -// -// payload string -// reason string -// signature string -// signer PayloadUser{...} -// verified boolean -// } -// } +use serde::{Deserialize, Serialize}; + +use crate::types::api::payload_user::PayloadUser; +use crate::types::misc::boolean_enums::is::verified::IsVerified; + +/// Represents the GPG verification of a commit. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PayloadCommitVerification { + /// The payload to be verified. + pub payload: String, + /// The reason for verification. + pub reason: String, + /// The GPG signature. + pub signature: String, + /// The user who signed the commit. + pub signer: PayloadUser, + /// Indicates whether the verification was successful. + pub verified: IsVerified, +} + +#[cfg(test)] +mod tests { + #[test] + fn deserialize_payload_commit_verification() { + let data = include_str!("../../../test_data/example_payload_commit_verification.json"); + let _: super::PayloadCommitVerification = serde_json::from_str(data).unwrap(); + } +} diff --git a/src/types/api/payload_user.rs b/src/types/api/payload_user.rs index 834cb6b..0b09fc2 100644 --- a/src/types/api/payload_user.rs +++ b/src/types/api/payload_user.rs @@ -1,10 +1,23 @@ -// PayloadUser{ -// description: -// PayloadUser represents the author or committer of a commit -// -// email string($email) -// name string -// Full name of the commit author -// -// username string -// } +use serde::{Deserialize, Serialize}; +use serde_email::Email; + +/// Represents the author or committer of a commit. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PayloadUser { + /// The email address of the user. + pub email: Email, + /// The full name of the user. + pub name: String, + /// The username of the user. + pub username: String, +} + +#[cfg(test)] +mod tests { + #[test] + fn deserialize_payload_user() { + let data = include_str!("../../../test_data/example_payload_user.json"); + + let _: super::PayloadUser = serde_json::from_str(data).unwrap(); + } +} diff --git a/src/types/misc/boolean_enums/can/mod.rs b/src/types/misc/boolean_enums/can/mod.rs index df31b15..3ce30eb 100644 --- a/src/types/misc/boolean_enums/can/mod.rs +++ b/src/types/misc/boolean_enums/can/mod.rs @@ -6,4 +6,5 @@ implement_boolean_enum!(read, CanRead); implement_boolean_enum!(write, CanWrite); implement_boolean_enum!(pull, CanPull); implement_boolean_enum!(push, CanPush); +implement_boolean_enum!(merge, CanMerge); implement_boolean_enum!(create_repo, CanCreateRepo); diff --git a/src/types/misc/boolean_enums/enable/mod.rs b/src/types/misc/boolean_enums/enable/mod.rs index 0d6121d..34ef069 100644 --- a/src/types/misc/boolean_enums/enable/mod.rs +++ b/src/types/misc/boolean_enums/enable/mod.rs @@ -2,3 +2,4 @@ use crate::implement_boolean_enum; implement_boolean_enum!(issue_dependencies, IssueDependencies { On, Off }); implement_boolean_enum!(time_tracker, TimeTracker { On, Off }); +implement_boolean_enum!(enable_status_check, EnableStatusCheck); diff --git a/src/types/misc/boolean_enums/is/mod.rs b/src/types/misc/boolean_enums/is/mod.rs index f8c0884..9c8d805 100644 --- a/src/types/misc/boolean_enums/is/mod.rs +++ b/src/types/misc/boolean_enums/is/mod.rs @@ -16,3 +16,5 @@ implement_boolean_enum!(ok, IsOk); implement_boolean_enum!(locked, IsLocked); implement_boolean_enum!(mergeable, IsMergeable); implement_boolean_enum!(merged, IsMerged); +implement_boolean_enum!(verified, IsVerified); +implement_boolean_enum!(protected, IsProtected); diff --git a/test_data/example_branch.json b/test_data/example_branch.json new file mode 100644 index 0000000..302bb20 --- /dev/null +++ b/test_data/example_branch.json @@ -0,0 +1,99 @@ +[ + { + "commit": { + "added": [ + "file1.txt", + "file2.txt" + ], + "author": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "committer": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "id": "abcdef123456", + "message": "Commit message", + "modified": [ + "file3.txt" + ], + "removed": [ + "file4.txt" + ], + "timestamp": "2023-10-21T14:30:00Z", + "url": "https://example.com/commits/abcdef123456", + "verification": { + "payload": "payload_data", + "reason": "Verification reason", + "signature": "gpg_signature", + "signer": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "verified": true + } + }, + "effective_branch_protection_name": "master", + "enable_status_check": true, + "name": "main", + "protected": true, + "required_approvals": 2, + "status_check_contexts": [ + "status-check-1", + "status-check-2" + ], + "user_can_merge": true, + "user_can_push": true + }, + { + "commit": { + "added": [ + "file1.txt", + "file2.txt" + ], + "author": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "committer": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "id": "abcdef123456", + "message": "Commit message", + "modified": [ + "file3.txt" + ], + "removed": [ + "file4.txt" + ], + "timestamp": "2023-10-21T14:30:00Z", + "url": "https://example.com/commits/abcdef123456", + "verification": { + "payload": "payload_data", + "reason": "Verification reason", + "signature": "gpg_signature", + "signer": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "verified": true + } + }, + "effective_branch_protection_name": "develop", + "enable_status_check": false, + "name": "develop", + "protected": false, + "required_approvals": 0, + "status_check_contexts": [], + "user_can_merge": true, + "user_can_push": true + } +] diff --git a/test_data/example_payload_commit.json b/test_data/example_payload_commit.json new file mode 100644 index 0000000..a2fb096 --- /dev/null +++ b/test_data/example_payload_commit.json @@ -0,0 +1,37 @@ +{ + "added": [ + "file1.txt", + "file2.txt" + ], + "author": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "committer": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "id": "abcdef123456", + "message": "Commit message", + "modified": [ + "file3.txt" + ], + "removed": [ + "file4.txt" + ], + "timestamp": "2023-10-21T14:30:00Z", + "url": "https://example.com/commits/abcdef123456", + "verification": { + "payload": "payload_data", + "reason": "Verification reason", + "signature": "gpg_signature", + "signer": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "verified": true + } +} diff --git a/test_data/example_payload_commit_verification.json b/test_data/example_payload_commit_verification.json new file mode 100644 index 0000000..815b0e2 --- /dev/null +++ b/test_data/example_payload_commit_verification.json @@ -0,0 +1,11 @@ +{ + "payload": "payload_data", + "reason": "Verification reason", + "signature": "gpg_signature", + "signer": { + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" + }, + "verified": true +} diff --git a/test_data/example_payload_user.json b/test_data/example_payload_user.json new file mode 100644 index 0000000..2e21087 --- /dev/null +++ b/test_data/example_payload_user.json @@ -0,0 +1,5 @@ +{ + "email": "user@example.com", + "name": "John Doe", + "username": "johndoe" +}