From b5d57249fa60c4883162e7a2d46a3f52380bc340 Mon Sep 17 00:00:00 2001 From: aviac Date: Fri, 22 Sep 2023 20:36:26 +0200 Subject: [PATCH] feat: implement CreateRepoOptions --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/types/api/creation/repository.rs | 71 +++++++++++++--------------- src/types/misc/boolean_enums/mod.rs | 1 + src/types/misc/mod.rs | 3 +- src/types/misc/trust_model.rs | 27 +++++++++++ 6 files changed, 64 insertions(+), 42 deletions(-) create mode 100644 src/types/misc/trust_model.rs diff --git a/Cargo.lock b/Cargo.lock index 3615002..fa6473a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,7 +224,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "forgejo-api-types" -version = "0.1.0" +version = "0.1.2" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 4d76e79..c03457e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "forgejo-api-types" -version = "0.1.1" +version = "0.1.2" 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 21560d0..06cdc5d 100644 --- a/src/types/api/creation/repository.rs +++ b/src/types/api/creation/repository.rs @@ -1,39 +1,32 @@ -//CreateRepoOption{ -//description: -//CreateRepoOption options when creating repository -// -//auto_init boolean -//Whether the repository should be auto-initialized? -// -//default_branch string -//DefaultBranch of the repository (used when initializes and in template) -// -//description string -//Description of the repository to create -// -//gitignores string -//Gitignores to use -// -//issue_labels string -//Label-Set to use -// -//license string -//License to use -// -//name* string -//uniqueItems: true -//Name of the repository to create -// -//private boolean -//Whether the repository is private -// -//readme [...] -//template boolean -//Whether the repository is template -// -//trust_model string -//TrustModel of the repository -// -//Enum: -//[ default, collaborator, committer, collaboratorcommitter ] -//} +use serde::{Deserialize, Serialize}; + +use crate::types::misc::boolean_enums::auto_init::AutoInit; +use crate::types::misc::boolean_enums::is::private::IsPrivate; +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)] +pub struct CreateRepoOption { + /// Whether the repository should be auto-initialized. + pub auto_init: AutoInit, + /// Default branch of the repository (used when initializes and in template). + pub default_branch: String, + /// Description of the repository to create. + pub description: String, + /// Gitignores to use. + pub gitignores: String, + /// Label-Set to use. + // 🚧🚧 TODO 🚧🚧 : Do better than comma separated list of names + pub issue_labels: String, + /// License to use. + pub license: String, + /// Name of the repository to create. + pub name: String, + /// Whether the repository is private. + pub private: IsPrivate, + /// Whether the repository is a template. + pub template: IsTemplate, + /// TrustModel of the repository. + pub trust_model: TrustModel, +} diff --git a/src/types/misc/boolean_enums/mod.rs b/src/types/misc/boolean_enums/mod.rs index 36c65c3..7b18721 100644 --- a/src/types/misc/boolean_enums/mod.rs +++ b/src/types/misc/boolean_enums/mod.rs @@ -10,3 +10,4 @@ implement_boolean_enum!(delete_branch_after_merge, DeleteBranchAfterMerge); implement_boolean_enum!(ignore_whitespace_conflicts, IgnoreWhitespaceConflicts); implement_boolean_enum!(includes_all_repositories, IncludesAllRepositories); implement_boolean_enum!(prohibit_login, ProhibitLogin); +implement_boolean_enum!(auto_init, AutoInit); diff --git a/src/types/misc/mod.rs b/src/types/misc/mod.rs index 5c32061..79df9f4 100644 --- a/src/types/misc/mod.rs +++ b/src/types/misc/mod.rs @@ -1,4 +1,4 @@ -/// bools suck muhahahahaha +/// bools suck muhahahahaha 😈 pub mod boolean_enums; pub mod color; pub mod external_issue_format; @@ -8,4 +8,5 @@ pub mod optional_url; pub mod permission; pub mod sshurl; pub mod team_permissions; +pub mod trust_model; pub mod visibility; diff --git a/src/types/misc/trust_model.rs b/src/types/misc/trust_model.rs new file mode 100644 index 0000000..c6e0209 --- /dev/null +++ b/src/types/misc/trust_model.rs @@ -0,0 +1,27 @@ +use clap::ValueEnum; +use serde::{Deserialize, Serialize}; +use strum::{Display, EnumIs, EnumIter, EnumString}; + +/// TrustModel represents the trust model of the repository. +#[derive( + Debug, + Clone, + Copy, + PartialEq, + Eq, + ValueEnum, + Display, + EnumIter, + EnumString, + EnumIs, + Serialize, + Deserialize, +)] +#[strum(serialize_all = "lowercase")] +#[serde(rename_all = "lowercase")] +pub enum TrustModel { + Default, + Collaborator, + Committer, + CollaboratorCommitter, +}